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
Its PERL + Comma separated seventh field ganapati Shell Programming and Scripting 17 06-24-2009 05:20 AM
field separator in Perl ahsog Shell Programming and Scripting 38 04-17-2009 09:30 PM
Perl sort unique by one field only Donkey25 Shell Programming and Scripting 2 03-20-2009 10:15 AM
perl regular expressions and field search dynamox Shell Programming and Scripting 4 09-02-2008 10:46 AM
[awk]: Row begins by random number and field 10 is greater than 10.00% Lomic Shell Programming and Scripting 3 03-18-2005 09:59 AM

Reply
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
  #1 (permalink)  
Old 10-01-2009
Donkey25 Donkey25 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 36
Perl if field begins with.......

Hi,

This must be simple but I can't get it to work. I have the follow code to insert the contents of a file into an array and then I want to print the value of a container where all of the records in another container within the array start with 33 (that's not all I want to do but it is all I want to do right now).


Code:
$file_name="/home/file1";
open(DATA, $file_name) || die ("Could not open file!");
@deliver_data=<DATA>;
close(DATA);

foreach $line (@deliver_data)
{
chop($line);
($id,$day,$ref,$originator,$destination,$type,$code)=split(/,/,$line);
}

if $destination /^33/;
{
print "$code";
}

I keep getting this error:


Code:
syntax error at ./andrews_perl_foreign_calc.pl line 27, near "if $destination "
Execution of ./andrews_perl_foreign_calc.pl aborted due to compilation errors.

Many thanks!
  #2 (permalink)  
Old 10-01-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,921
Rewrite
Code:
if $destination /^33/;

to
Code:
if ( $destination =~ /^33/ )

'if' doesn't need a semi-colon at the end, conditions should be in braces, and regular expressions are mapped with the '=~' operator.
  #3 (permalink)  
Old 10-01-2009
Donkey25 Donkey25 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 36
Perfect, many thanks for your help
Reply

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 05:10 PM.


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