Perl- How to catch the file in perl code?


 
Thread Tools Search this Thread
Top Forums Programming Perl- How to catch the file in perl code?
# 1  
Old 07-18-2011
Perl- How to catch the file in perl code?

Hi,
plz see the below code , i have catch the file "Orders.20110714.out "file
as a Orders*.out. but it giving me an error .it does not open the file.

if the same thing i have done by code

code-> ls Orders*.out then it gives me the output
Orders.20110714.out

i am trying apply the same concept ne below code but it is not working

can anyone help me regarding this???

==============================================

Code:
#!/usr/bin/perl -w
$ARGV[0]||='/home/user01/Orders*.out';
$linenum=0;
open OR,$ARGV[0];
local $/="\r";
while (<OR>) {
$linenum++;
}
#close OR;
print $linenum;
close OR;

===============================================

Regards,
Priyanka

---------- Post updated at 02:14 PM ---------- Previous update was at 11:03 AM ----------

Hi all, need ur help

Last edited by pludi; 07-18-2011 at 04:55 AM..
# 2  
Old 07-18-2011
Use file globbing (<*.out>) while opening the file ( read more about glob in perl )

Code:
open OR,</home/sathiya/perl/Orders*.out>;

Not an excellent method to do so, but it works.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

3. Shell Programming and Scripting

PERL code to check if file exists

Hi Guy’s, I have this simple PERL code which checks whether the file exists . At the moment I am getting the following error This is the code I am using #!/usr/bin/perl Open (F, "home/work/PerlWork/dataFile") or die "Could not open the file:$!\"; Also how can I read the content of... (3 Replies)
Discussion started by: INHF
3 Replies

4. Shell Programming and Scripting

perl: a way to see a sub code in debug mode: perl -de 0 ?

Is there a way to see or print a sub code? Sometime a sub could be already defined, but in the debug mode (so, interactively) it could be already out of screen. So, I would think about a way to check if the sub is defined (just 'defined' is not a problem) and how it is defined. Also, if... (4 Replies)
Discussion started by: alex_5161
4 Replies

5. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

6. Shell Programming and Scripting

perl file, one line code include "length, rindex, substr", slow

Hi Everyone, # cat a.txt a;b;c;64O a;b;c;d;ee;f # cat a.pl #!/usr/bin/perl use strict; use warnings; my $tmp3 = ",,a,,b,,c,,d,,e,,f,,"; open(my $FA, "a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\;/, $_); if ( ($tmp =~ m/^(64O)/i) || ($tmp... (3 Replies)
Discussion started by: jimmy_y
3 Replies

7. Shell Programming and Scripting

Need help in comparing a file with log file: perl code

Dear Members, I need a perl code: 1. Which will open first file with two columns separated by tab: 37 Distribution and seasonal variation of trace metals 85 Seasonal variability of the mixed layer in the central Bay 99 Dynamics of transparent exopolymeric particles (TEP) 103 Bacterial... (0 Replies)
Discussion started by: srsahu75
0 Replies

8. Shell Programming and Scripting

Perl : Process a file in perl

I have a file with following data : Qspace: COLOR: Queue: doColor Qspace: COLOR: Queue order: fifo Qspace: COLOR: Out of order: none Qspace: COLOR: Retries: 5 Qspace: COLOR: Queue: setColor Qspace: COLOR: Queue order: fifo Qspace: COLOR: Out of order: none Qspace: COLOR: Retries: 5... (4 Replies)
Discussion started by: deo_kaustubh
4 Replies

9. Shell Programming and Scripting

Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl

Hi , This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated. use Time::Local; my $d = $ARGV; my $t = $ARGV; my $m = ""; @d = split /\//, $d; @t = split /:/, $t; if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies

10. Shell Programming and Scripting

perl -write values in a file to @array in perl

Hi can anyone suggest me how to write a file containing values,... say 19 20 21 22 .. 40 to an array @array = (19, 20, ... 40) -- Thanks (27 Replies)
Discussion started by: meghana
27 Replies
Login or Register to Ask a Question