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-like split function for bash? eur0dad Shell Programming and Scripting 5 09-05-2008 06:23 PM
sort function in perl DILEEP410 Shell Programming and Scripting 2 09-14-2007 08:03 AM
accessing a function in ksh from perl ahtat99 Shell Programming and Scripting 2 01-15-2007 08:38 AM
perl split function new2ss Shell Programming and Scripting 5 06-08-2006 10:17 PM
perl function call tracking thumper Shell Programming and Scripting 1 11-24-2005 09:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-15-2005
avadhani avadhani is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 15
PERL function problem

I have perl script as follow.
------------------------------------------------------------------------
#! /usr/bin/env perl

use strict;

sub printLines
{
print "Inside the function.............\n";
my (@file , $count , $key ) = $_;
print $count , $ key ; # It does not print this. ?

}
open(READ_FILE ,"simple.txt");
my @fa = <READ_FILE>;
my $symbolkey = "MY_SYMBOL";
my $line;
foreach $line (@fa){
if ($line =~ /$symbolkey/) {
print $line ,"Match found .............\n";
&printLines(@fa,3,$symbolkey);
}
}
close(READ_FILE);

-------------------------------------------------------------------

Function gets called. But inside function , it does not print values of arguments. What is problem with it.

Thank you,
  #2 (permalink)  
Old 06-15-2005
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
Quote:
Originally Posted by avadhani
my (@file , $count , $key ) = $_;
Use '@_' instead of '$_'. And you simply should not pass an array directly if the subroutine signature contains a mixture of scalar and list data values, because the @file in your example will gobble up all parameters leaving $count and $key undef, even if you have made the change I mentioned above.

Pass by reference.

Code:
my ($r_file , $count , $key ) = @_;
my @file = @$r_file;
And change the way you call the subroutine:

Code:
&printLines(\@fa,3,$symbolkey);
  #3 (permalink)  
Old 06-15-2005
avadhani avadhani is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 15
Hi,
Thank you for the clarification. Now it is working.
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 07:22 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