Loading ...
Sorry, an error occurred while loading the content.
 

Re: [PBML] Name of current file

Expand Messages
  • Shawn Corey
    ... $ARGV works only inside the read loop. It will be undef until the first read. #!/usr/bin/perl use strict; use warnings; my $file = $ARGV; print $file =
    Message 1 of 4 , Sep 21, 2005
      Bobby Jafari wrote:
      > $ARGV contains the name of the current file when reading from <>.
      >
      > <> is the STDIN but I am unsure how to read the current file name.
      >
      > ie:
      >
      > my ($FileName) = $ARGV;
      >
      > Or
      >
      > my ($FileName) = <$ARGV>;
      >
      > Needless to say that the above two line did not return the file name.
      >
      > Regards,

      $ARGV works only inside the read loop. It will be undef until the first
      read.

      #!/usr/bin/perl

      use strict;
      use warnings;

      my $file = $ARGV;
      print "\$file = $file\n";

      while( <> ){
      $file = $ARGV;
      print "$file: $_";
      }

      __END__


      --- Shawn
    Your message has been successfully submitted and would be delivered to recipients shortly.