possible link/ARGV problem?

Discussion in 'Perl Misc' started by courtney.machi@gmail.com, Nov 2, 2005.

  1. Guest

    Hello,

    I am writing 2 scripts - s2 parses logfiles located in a different
    directory, s1 calls s2 and provides the path to the logfiles. When i
    run s1, it appears to be reading the logfile but not writing anything.
    when i run s2 (although not necessary) it says 'can't open logfile: no
    such file or directory'. I am assigning the $host = ARGV[0] and
    $logfile = ARGV[1] in s2, then in s1 looping through each logfile and
    calling s2 to parse and write. Hopefully this is not too ambiguous -
    does anyone have any suggestions??

    Thanks,
    Courtney
    , Nov 2, 2005
    #1
    1. Advertising

  2. Guest

    by the way, here is a snippet of code:

    $host = $ARGV[0];
    $logfile = $ARGV[1];

    # Initialize record counters.
    $n_read = $n_written = 0;
    $n_other_user = $n_other_time = $n_stdin_acctcom = 0;

    $last_entry = '';

    # Parse the log file.

    open(IN,"<$logfile") || die "can't open log file $logfile: $!\n"; <---
    at this line i am getting this error: Use of uninitialized value in
    concatenation (.) or string
    ??
    , Nov 2, 2005
    #2
    1. Advertising

  3. Paul Lalli Guest

    wrote:

    > I am writing 2 scripts - s2 parses logfiles located in a different
    > directory, s1 calls s2 and provides the path to the logfiles. When i
    > run s1, it appears to be reading the logfile but not writing anything.
    > when i run s2 (although not necessary) it says 'can't open logfile: no
    > such file or directory'. I am assigning the $host = ARGV[0] and


    What language is that? In Perl, the arguments are kept in @ARGV, so
    you'd access the first one with

    $host = $ARGV[0];

    > $logfile = ARGV[1] in s2, then in s1 looping through each logfile and
    > calling s2 to parse and write. Hopefully this is not too ambiguous -
    > does anyone have any suggestions??


    Suggestions:
    * minimize your scripts to the shortest possible example that still
    demonstrates your error.
    * Make sure you're using strict and warnings
    * print the filename you're attempting to open in the error output.
    Rather than `die "Cannot open logfile: $!"`, make it `die "Cannot open
    logfile '$logfile': $!"`
    * if the above three suggestions don't help you find your answer,
    provide us with the minimized scripts - in a form we can run by copy
    and pasting.

    Paul Lalli
    Paul Lalli, Nov 2, 2005
    #3
  4. Joe Smith Guest

    wrote:
    > by the way, here is a snippet of code:


    Your snippet did not show the script verifying its arguments.

    > $host = $ARGV[0];
    > $logfile = $ARGV[1];


    my $Usage = "Usage: $0 host logfile\n";
    my $host = $ARGV[0] or die "Host name missing\n",$Usage;
    my $logfile = $ARGV[1] or die "Log file name missing\n",$Usage;

    > open(IN,"<$logfile") || die "can't open log file $logfile: $!\n";


    open my $in,'<',$logfile or die "Can't open log file $logfile: $!\n";

    > at this line i am getting this error: Use of uninitialized value in
    > concatenation (.) or string


    So, how exactly are you invoking your second script?
    Anything like this:
    system('s2.pl',$host,$logfile) == 0 or die "Failed: s2.pl $?";
    or
    $result = `./s2.pl $host $logfile`
    die "No results from s2: $?\n" if $? or $result eq "";

    -Joe
    Joe Smith, Nov 12, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bret

    char **argv vs. char* argv[]

    Bret, Aug 31, 2003, in forum: C Programming
    Replies:
    21
    Views:
    4,586
    Richard Heathfield
    Sep 3, 2003
  2. David
    Replies:
    10
    Views:
    5,952
    Richard Heathfield
    Sep 15, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,634
    Old Wolf
    Jan 20, 2004
  4. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    sys.argv[0] - 'module' object has no attribute 'argv'

    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    902
    =?ISO-8859-1?Q?Thomas_N=FCcker?=
    Jun 30, 2003
  5. jab3

    char **argv & char *argv[]

    jab3, Dec 4, 2004, in forum: C Programming
    Replies:
    5
    Views:
    665
    Chris Torek
    Dec 8, 2004
Loading...

Share This Page