in reply to Re: Arrays of files from an array of file names
in thread Arrays of files from an array of file names

I do NOT want to sound ingrateful.....but, I'm trying your code and failing miserably.:
#!/usr/bin/perl -w use strict; my $file1 = "trixee"; #just some nicknames! my $file2 = "limo"; my $file3 = "nata"; my @files = qw(file1 file2 file3); my @contents; foreach (@files) { open FILE, $_ or do { warn "Can't open $_: $!\n"; next } push @contents, [<FILE>]; } foreach my $tmp(@contents) { print "$tmp\n"; }
This fails with:

"syntax error at ./testsub.pl line 16, near "push"
"Execution of ./testsub.pl aborted due to compilation errors".

Any ideas?

Replies are listed 'Best First'.
Re: What am I doing wrong?
by japhy (Canon) on Feb 19, 2001 at 07:11 UTC
    First, are you sure @files isn't supposed to be ($file1, $file2, $file3)? Right now, you're just setting it to the STRINGS ('file1', 'file2', 'file3').

    Anyway, you're missing the semicolon at the end of the do BLOCK expression on line 14. do BLOCK turns a BLOCK (which DOESN'T need a semicolon at the end) into an expression.

    And you can get away from that by doing:
    open FILE, $_ or warn("...: $!"), next;


    japhy -- Perl and Regex Hacker