Hello, Newbie here,
I am trying to use a while loop to read through all of the values in a file, but the filenames contain an '@'.
I have the directory path in a variable, and the filenames in an array. So far I have tried using quotemeta to backslash special characters, which seems to print the correct values but this does not seem to work in my open command. I think maybe I have a problem with using the correct quoting??
Thanks in advance for any help, here is what I have so far:
my $Line_QC = "/full/directory/path"; opendir(DIR, "$Line_QC") or die $!; my @files_array = grep { /^35_/ && -f "$Nav_Line_QC/098/$_"} readdir(DIR); my $diag_file = quotemeta"@files_array[0]"; print "@diag_files_array[0]\n"; # prints: 35_Diag_098_a098@421424012017.txt print "$diag_file\n"; # prints: 35_Diag_098_a098\@421424012017\.txt open ( DIAG, "$diag_file" ) ||die ("Failed: $!"); while (my $line = <DIAG>) { if ($line =~ /Line/) { print "$line\n"; }; }; # Close while loop close ( DIAG );
Running this gives me the error: No such file or directory at perlTest line 60.
In reply to Dealing with files that contain '@' in the filename by elef4nt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |