The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
perl -write values in a file to @array in perl meghana Shell Programming and Scripting 27 06-07-2009 05:05 PM
UNIX newbie NEWBIE question! Hanamachi UNIX for Dummies Questions & Answers 4 03-28-2009 04:10 PM
[PERL] Running unix commands within Perl Scripts userix Shell Programming and Scripting 1 05-28-2008 06:06 PM
perl newbie: how to extract an unknown word from a string wolwy_pete Shell Programming and Scripting 3 03-23-2008 10:41 AM
Perl newbie question ssmiths001 Shell Programming and Scripting 2 05-08-2006 12:20 PM

Closed Thread
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 04-24-2008
Khoomfire Khoomfire is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 68
Perl Newbie - help!

Hi All,
newbie-ish question here. I have this script:

Code:
foreach $test (@num)
{
foreach $record (@neet)
{
if ($record =~ /$test/){
print "$record \n";
print $test;
}
}
}
For some reason, the $test variable doesn't seem to be carrying into the second "foreach" loop. Does anyone know why this is so? I suspect it might be an issue with the "$" character having a special meaning within REs. Please assist.
Edit/Delete Message
  #2 (permalink)  
Old 04-24-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Works for me. What's in the @num array? Perhaps something which doesn't match what you think it ought to match? Or perhaps the missing newline after $test was throwing you off.

Code:
vnix$ cat neet
#!/usr/bin/perl

my (@num) = qw(foo bar baz);
my (@neet) = qw (food bar moobaz);

foreach $test (@num)
{
    foreach $record (@neet)
    {
        if ($record =~ /$test/)
	{
	    print "$record\n";
	    print $test;
	    print "\n";  # I assume you want, too
	}
    }
}
vnix$ perl neet
food
foo
bar
bar
moobaz
baz
Closed Thread

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 11:32 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