Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileName with trailing Pipe

Status
Not open for further replies.

LAdProg2005

Programmer
Feb 20, 2006
56
US
Hello all,

i am trying to read file that has pipe in the end of file name.

fileOne| -> it is a data file

./test fileOne| doesn't work as it doesn't read the |

I tried to escape it with backslash
./test fileOne\| but this doesn't work also

Code:
$opF = $ARGV[0];

      open FILE, "$opF" or die "$!";
      while(<FILE>)
      {
        $line = $_;
        print "$line\n";
      }

any help will be appreciated
thank you
lad
 
Two things:
1. First you will need to quote the file name so your shell knows that you are not trying to pipe test.pl's output:
./test.pl "fileOne|"

2. Second, you should use the 3 argument mode of open.

Something like:
Code:
open FILE, '<', $opF or die "$!";
 
1. First you will need to quote the file name so your shell knows that you are not trying to pipe test.pl's output:
./test.pl "fileOne|"

For this, it still says
Can't exec "fileOne": No such file or directory at ./test.pl line 8.

Thanks
 
Try single quotes. Some shells (bash for example) try to interpolate things still inside double quotes (for example any $ in double quotes bash mistakes for trying to insert a bash variable).

Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
bengR's second suggestion seems to fix it for me. What OS and shell are you using?

Code:
$ cat test
#!/usr/bin/perl -w
use strict;
my $opF = $ARGV[0];

open FILE, '<', $opF or die "$!";
while(<FILE>)
{
        my $line = $_;
        print "$line";
}
$ cat fileOne\|
             Mar 2010
Sun  Mon  Tue  Wed  Thu  Fri  Sat
      1    2    3    4    5    6
 7    8    9   10   11   12   13
14   15   16   17   18   19   20
21   22   23   24   25   26   27
28   29   30   31

$ ./test fileOne\|
             Mar 2010
Sun  Mon  Tue  Wed  Thu  Fri  Sat
      1    2    3    4    5    6
 7    8    9   10   11   12   13
14   15   16   17   18   19   20
21   22   23   24   25   26   27
28   29   30   31

$ ./test 'fileOne|'
             Mar 2010
Sun  Mon  Tue  Wed  Thu  Fri  Sat
      1    2    3    4    5    6
 7    8    9   10   11   12   13
14   15   16   17   18   19   20
21   22   23   24   25   26   27
28   29   30   31

$

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top