Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Help with perl error message

by dimmesdale (Friar)
on Jun 25, 2002 at 13:13 UTC ( #177077=perlquestion: print w/ replies, xml ) Need Help??
dimmesdale has asked for the wisdom of the Perl Monks concerning the following question:

I wrote a program to order some output I had from another file. (Tab delimited; first column is the file name; I'm looking for certain letters in the file name). WHen I run this code, I get an error saying 'No comman allowed after file handle, line 42'. The line in question will be marked.

I don't understand it, because $i_file opens normally, and the only difference between $i_ and $o_file is the '>'. I don't even know what comma it's talking about!

#!/usr/bin/perl use warnings; use strict; my $i_file = "faster_averages.txt"; my $o_file = ">ordered_averages.txt"; my @i; my $j = 0; my @CCFN; my @CCFN_NT; my @EBG; my @EBGFN; my @PR; my @PRFN; my @BL; my @BLSTDG; my @BLSTDGG; my @output; open(IN, $i_file) or die "$i_file failed to open: $!"; my @lines = <IN>; close IN; for my $file ((split /\t/, @lines)[0]) { if($file =~ /CCFN\d+NT/) { $CCFN_NT[$i[0]++] = $lines[$j] } if($file =~ /CCFN/) { $CCFN[$i[1]++] = $lines[$j] } if($file =~ /EBGFN/) { $EBGFN[$i[2]++] = $lines[$j] } if($file =~ /EBG/) { $EBG[$i[3]++] = $lines[$j] } if($file =~ /PRFN/) { $PRFN[$i[4]++] = $lines[$j] } if($file =~ /PR/) { $PR[$i[5]++] = $lines[$j] } if($file =~ /BLSTDGG/) { $BLSTDGG[$i[6]++] = $lines[$j] } if($file =~ /BLSTDG/) { $BLSTDG[$i[7]++] = $lines[$j] } if($file =~ /BL/) { $BL[$i[8]++] = $lines[$j] } $j++; } @output = (@CCFN,@CCFN_NT,@EBG,@EBGFN,@PR,@PRFN,@BL,@BLSTDG,@BLSTDGG); ######## # Right here open(OUT, $o_file) or die "$o_file failed to be created: $!"; # $o_file defined above ######## print OUT, @output; close OUT;

Comment on Help with perl error message
Download Code
Replies are listed 'Best First'.
Re: Help with perl error message
by particle (Vicar) on Jun 25, 2002 at 13:18 UTC
    there's a rogue comma in your print statement

    ## print OUT, @output; print OUT @output;
    umm... that's why it says 'no comma allowed after filehandle' :)

    ~Particle *accelerates*

Re: Help with perl error message
by RMGir (Prior) on Jun 25, 2002 at 13:18 UTC
    You marked the wrong line.

    The problem is the print statement on the NEXT line, where you have

    print OUT, @output;
    That should be:
    print OUT @output;
    Sometimes perl misreports error line numbers, but I don't think it would get this one wrong; you may want to double-check.
    --
    Mike
Re: Help with perl error message
by Zaxo (Archbishop) on Jun 25, 2002 at 13:21 UTC

    You've misidentified the line with the error:

    ######## # Right here open(OUT, $o_file) or die "$o_file failed to be created: $!"; # $o_file defined above ######## print OUT, @output; # ^ Here it is -- Z. close OUT;
    The error is as marked, in the print statement.

    After Compline,
    Zaxo

Re: Help with perl error message
by frankus (Priest) on Jun 25, 2002 at 13:21 UTC
    Thought of trying use diagnostics;?
    Also consider moving those arrays to anonymous arrays in a hash.
    # List all search criteria
    my @search = ( 'CCFN\d+NT','CCFN',
                   'EBGFN','EBG',
                   'PRFN','PR',
                   'BLSTDGG','BLSTDG','BL');
    
    # Build an index of the fields they correspond to
    my %index = map{ $earch$_ => $_ } (0..$#search);
    
    # Make a hash to store the results
    my %results = map { $_ => [] }@search;
    
    # Make a generic regex, for one pass.
    my $regex = join( '|' map{"($_)"}@search);
    
    # Blah blah split and stuff. 
    
    # Use the bracketed results of the regex to store data.
    m/$regex and push @{$results{$1}}, $line[$index{$1};
    
    print Dumper \@results{@search};
    

    --

    Brother Frankus.

    ¤

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://177077]
Approved by particle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2015-08-02 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found
    past polls