blue_cowdawg has asked for the wisdom of the Perl Monks concerning the following question:

Consider the following code:

#!/usr/bin/perl use strict; use File::Remote; my $rp=new File::Remote( rsh=>"/usr/bin/ssh", rcp=>'/usr/bin/scp'); $rp->open (ARPFILE,"xeng-mon01:/usr/local/router-walk/data/arp.csv") or die $!; my $line=<ARPFILE>; print $line;
When that is run I get an error:
Bareword "ARPFILE" not allowed while "strict subs" in use at testFileR +emote.pl line 8.
which confuses the heck out of me. When I do something like
#!/usr/bin/perl use strict; open FIN,"</etc/passwd" or die $!; my $line=<FIN>; print $line;
it gives me the first line of my /etc/passwd file just like I'd expect. What gives here? Anybody else see this?

Or am I getting senile in my old age?


UPDATE: Since posting this and before reading the replies from folks (Thanks shmem, rblaschand Herkum!) I had two beers and tried an experiment and it worked. By changing the first example's open call to

$rp->open(*ARPFILE....
strict was happy again. Then I read the replies and discovered why it worked. Thanks again gang! </code>


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re: File::Remote wierdness. (problems using strict?)
by shmem (Chancellor) on Jun 21, 2006 at 18:11 UTC
    maybe... ;-)

    but $rp->open is just a sub, not even prototyped, so it's first argument isn't made into a filehandle.

    Hint: what happens if you use $rp->open (*ARPFILE,"xeng-mon01:/usr/local/router-walk/data/arp.csv")?

    cheers,
    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: File::Remote wierdness. (problems using strict?)
by Herkum (Parson) on Jun 21, 2006 at 19:51 UTC

    As the previous poster stated, you are not calling open directly. You are calling the method $r->open(). A method is going to expect that you are passing an array of values.

    Unqouted words have different means with different context,

    my %hash = ( red => 'car' ); # Hash context
    last STATEMENT; # label context
    open FILE, "my_file.txt"; # file handle context
    $r->open( ARGS ); # looking for an array, and the interpreter is thin +king, # it cannot be a label or file handle and it is not + a hash, WTF?
    I hope that helps some. Context of certain syntax can be confusing if you had not been doing it for a while, a loooong while! :) Note: This is within the context of 'use strict'.
Re: File::Remote wierdness. (problems using strict?)
by rblasch (Monk) on Jun 21, 2006 at 19:43 UTC

    Not sure if I get everything right, but here's the story. Usually, under use strict you are not allowed to use barewords like ARPFILE. A bareword is something perl "can't make sense of," thus it treats it as a quoted string 'ARPFILE' if there isn't any stricture. That's why you get the error.

    Unusually, there are some internal functions, like your open example, where barewords are okay, even under use strict, because they are meant as handles. opendir, sysopen and a few others seem to fall into this category. That's why your last example open FIN,"</etc/passwd" or die $!; works fine, even if FIN is a bareword.

    Your call to File::Remote::open $rp->open (ARPFILE,...) on the other hand is nothing but a plain method call, hence the error.

    It wouldn't be Perl if there weren't a few ways to solve this. Here's how I would do it. I prefer lexicals, so I'd create an anonymous glob with gensym using Symbol. Then one can usually use $arpfile like any other handle. Note that the following is untested.

    #!/usr/bin/perl use strict; use warnings; use File::Remote; use Symbol; my $rp = new File::Remote( rsh=>"/usr/bin/ssh", rcp=>'/usr/bin/scp'); my $arpfile = gensym; $rp->open ($arpfile,"xeng-mon01:/usr/local/router-walk/data/arp.csv") or die $!; my $line=<$arpfile>; print $line;

    Let me know if this is working for you.