syntax $_[0]

  • Thread starter Jon Landenburer
  • Start date
J

Jon Landenburer

I inherited a small perl program. It has this syntax whjich I donnot
iunderstand.

while (<FDF>)
{
$value = $_;
if ($_[0])
{ print TEMP $value;
next;
}
$service_order = substr( $value, 21, 18);
if ( $_[1] ) { $last_so = $service_order;} ## record 1 force
feed
. . .
. . .


Its the $_[0] I dont understand. If this were a subroutine I would
understand that tto be the first passed parameter. But this is not a
subroutine . I see the comment indicating that $_[1] but that line
never gets hit
 
P

Paul Lalli

I inherited a small perl program. It has this syntax whjich I donnot
iunderstand.

while (<FDF>)
{
$value = $_;
if ($_[0])
{ print TEMP $value;
next;
}
$service_order = substr( $value, 21, 18);
if ( $_[1] ) { $last_so = $service_order;} ## record 1 force
feed
. . .
. . .


Its the $_[0] I dont understand. If this were a subroutine I would
understand that tto be the first passed parameter. But this is not a
subroutine . I see the comment indicating that $_[1] but that line
never gets hit

Unless @_ is defined elsewhere in the program, in code you haven't shown
us, this is non-sensical, and neither if statement should be executed.

Paul Lalli
 
T

Tad McClellan

Jon Landenburer said:
if ($_[0])

Its the $_[0] I dont understand. If this were a subroutine I would
understand that tto be the first passed parameter. But this is not a
subroutine .


Is is accessing the array named underscore ( @_ ).

Since it is not in a subroutine, @_ is not populated automatically,
it must have been populated explicitly somewhere.

Find out where. :)
 
B

Ben Morrow

Quoth (e-mail address removed):
Jon Landenburer said:
if ($_[0])
Its the $_[0] I dont understand. If this were a subroutine I would
understand that tto be the first passed parameter. But this is not a
subroutine .

Is is accessing the array named underscore ( @_ ).

Since it is not in a subroutine, @_ is not populated automatically,
it must have been populated explicitly somewhere.

Or, perhaps, implicitly by split in scalar context.

Ben
 
J

Jon Landenburer

Paul Lalli said:
I inherited a small perl program. It has this syntax whjich I donnot
iunderstand.

while (<FDF>)
{
$value = $_;
if ($_[0])
{ print TEMP $value;
next;
}
$service_order = substr( $value, 21, 18);
if ( $_[1] ) { $last_so = $service_order;} ## record 1 force
feed
. . .
. . .


Its the $_[0] I dont understand. If this were a subroutine I would
understand that tto be the first passed parameter. But this is not a
subroutine . I see the comment indicating that $_[1] but that line
never gets hit

Unless @_ is defined elsewhere in the program, in code you haven't shown
us, this is non-sensical, and neither if statement should be executed.

Paul Lalli

Thanks Paul, That was exactly my figuring. I thought possibly it was
a piece of syntax I did not understand. I have removed those
statements after testing and ,correctly, they do nothing.
Jonl
 
S

Sara

I inherited a small perl program. It has this syntax whjich I donnot
iunderstand.

while (<FDF>)
{
$value = $_;
if ($_[0])
{ print TEMP $value;
next;
}
$service_order = substr( $value, 21, 18);
if ( $_[1] ) { $last_so = $service_order;} ## record 1 force
feed
. . .
. . .


Its the $_[0] I dont understand. If this were a subroutine I would
understand that tto be the first passed parameter. But this is not a
subroutine . I see the comment indicating that $_[1] but that line
never gets hit

Not seeing the entire context it's difficult to say. Perhaps this
"used to be" subroutine code that was moved into main and this was
overlooked?

Here's a hint- run it with "perl -wd", and examine the contents ot
$_[0] or @_ on that line. If it's undef then you probably have a
problem.

G
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top