Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: redrafted code

by wind (Priest)
on Feb 02, 2011 at 06:18 UTC ( [id://885666]=note: print w/replies, xml ) Need Help??


in reply to redrafted code

Well, one problem is your function call is embedded in a string where it won't be called. Take this
print $oh "$NO\n", "events($@list)\n", "$SEC1, $LONG, $LAT, $DEPTH, $G +AP\n";
to
print $oh "$NO\n", events($@list), "\n$SEC1, $LONG, $LAT, $DEPTH, $GAP +\n";
Also, in case anyone else wants to help further, here's the code with better spacing.
#!/usr/bin/perl; use strict; use warnings; my $fin = "SELECTDAT2"; my $fout = "myfile"; open my $ih, '<', $fin or die "cannot open $fin for reading, $! "; open my $oh, '>', $fout or die "cannot open $fout for writing, $! "; while (<$ih>) { my @tokens = split; my $SEC1 = $tokens[4]; my $LAT = $tokens[5]; my $LONG = $tokens[6]; my $DEPTH = $tokens[7]; my $NO = $tokens[11]; my $GAP = $tokens[12]; my $nextline = <$ih>; $nextline; my $y = $tokens[0]; my $m = $tokens[1]; my $d = $tokens[2]; my $h = $tokens[3]; sub events { my @list; foreach $nextline (@list) { if ($nextline le $NO) { my @tokens = split; my $SOURCE = $tokens[0]; my $PSEC = $tokens[4]; my $PQ = $tokens[5]; my $SSEC = $tokens[8]; my $SQ = $tokens[9]; push (@list, $_); } } return @list; } last line if $nextline eq ""; print $oh "$NO\n", events($@list), "\n$SEC1, $LONG, $LAT, $DEPTH, +$GAP\n"; } close ($oh); close ($ih);

- Miller

Replies are listed 'Best First'.
Re^2: redrafted code
by velocitymodel (Acolyte) on Feb 02, 2011 at 06:27 UTC

    Thanks!! I was having trouble figuring out how to call subroutines in perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://885666]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 19:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found