The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help on Mulitple files mutliple actions saariko Shell Programming and Scripting 1 01-16-2009 03:35 AM
Opening Files and checking contents in Perl Raynon Shell Programming and Scripting 7 09-02-2008 10:33 AM
Perl: Opening a filehandle but not getting anything back from it Smiling Dragon Shell Programming and Scripting 8 08-16-2008 03:40 AM
Opening files saarshad001 UNIX for Dummies Questions & Answers 3 11-28-2003 12:42 PM
Opening Perl perleo Shell Programming and Scripting 2 08-26-2002 10:41 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-06-2009
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Opening Mulitple files using For loop in Perl

Hi All,

I have a total of ten file to open in the Perl script and i am using a for loop to open each file and capture some strings inside each file.
Unfortunately, i encounter the below syntax error.
I think there should be something wrong with this term reports_${counting}_${_[0]}.txt but i do not know how to modify the code to suit this.
Can any expert help me with this ?

The file names which i wish to open are :
reports_1_MAIN
reports_2_MAIN
reports_3_MAIN
...
...
reports_10_MAIN





Code:
#!/usr/local/bin/perl

use Env;               # for processing environment variables
use strict;
use warnings;

my $test = "MAIN";
capture_LOT_DATE ($test);
 

sub capture_LOT_DATE {
            my $counting = 1;
            my @fields;
            my @DATE;
            my @date;
            my @lotsuffix;
   
             for ($counting = 1; $counting <= 10 ; $counting++ ) {
                     open(FH, "< $HISTORY/reports_${counting}_${_[0]}.txt" ) or die $!;
                             while( <FH> ) {
                                     my @Fld = split(' ', reports_${counting}_${_[0]}.txt);
                                     if ( $Fld[1] eq 'LOTSUFFIX=' ) {
                                             $lotsuffix[$counting] = $Fld[2];
                                             last;
                                     }
                                    if ( $Fld[1] eq 'DATE=' ) {
                                             $DATE[$counting] = $Fld[2];
                                            @fields = split(/-/, $DATE[$counting]);
                                             $date[$counting] = sprintf {"%s-%s",$fields[1],$fields[2]};
                                     }
                             }
                             close FH;
             }
}


Syntax Error

Code:
Bareword found where operator expected at near "${counting}_"
        (Missing operator before _?)
Bareword "txt" not allowed while "strict subs" in use 
Bareword "files_extracted" not allowed while "strict subs" in use 
Bareword "txt" not allowed while "strict subs" in use

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0