in reply to Newbie Question - arrays

The quick fix to your problem is to change
print "$array[\"$current\"]";
to
print "$array[$current]";
since you really don't want to be escaping those quotes. Or, try
print $array[$current];
since there's no need to stringify a value that is already a string.

The longer fix is to find one of the recipes for scanning mailbox files. The Perl Cookbook is an essential reference to have within reach when you're doing tasks like this.

Replies are listed 'Best First'.
Re: Re: Newbie Question - arrays
by mohadib_the_nasty (Initiate) on Jan 13, 2003 at 03:35 UTC
    thank you
    I changed the script like you said. Looks better,
    but i still get the errors. the mail que has
    one mail in it and here is the out put of the script...

    root ns2 perl_scratch--->./mail.pl
    Linux ns2.taproot.bz 2.4.18-3 #1 Thu Apr 18 07:32:41 EDT 2002 i686 unknown
    8:46pm up 33 min, 4 users, load average: 0.00, 0.00, 0.00
    Sat Jan 11 20:46:21 MST 2003
    Use of uninitialized value in string at ./mail.pl line 15.
    Use of uninitialized value in string at ./mail.pl line 15.
    Use of uninitialized value in string at ./mail.pl line 15.

    as i mentioned before i belive the problem is
    line 15 trying to call vars from @array that dont exist.
    Im just not sure on how to fix it. Or if my logic to start
    with is sound.

    Thanks for the tip,
    jd