Visit Our UNIX and Linux User Community


Perl system fuction with


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl system fuction with
# 1  
Old 09-24-2009
Perl system fuction with

Hi,

I've written a perl script with a nested foreach statement in it.

I have the line

code:
foreach $argn(@arguments) {
foreach $location (@path) {
system("find $location -name \"$argn\" -print >> results.txt");

open(DATAFILE2, "results.txt") || die "cannot find results.txt file";
@results=<DATAFILE2>;
close(DATAFILE2);

#Print results
foreach (@results) {
print;
}
system("rm results.txt");
}

}


The problem is the system("find $location -name \"$argn\" -print >> results.txt"); seems to only return the results of system("find $location
and gives “sh: line 2: -name: command not found” error

To test if it was my code, I hardcoded the $location variable and the $argn variable, and that worked fine.

Any ideas why using the argns isn't working?
# 2  
Old 09-24-2009
You have new line in $location.

Kindly chomp it before giving it as argument.
# 3  
Old 09-24-2009
thanks thegeek, i feel so stupid for not noticing that.

adding
chomp($location);
chomp ($argn);

did the trick. Def need abit more practise with perl after that...

---------- Post updated at 07:06 AM ---------- Previous update was at 06:44 AM ----------

To add to this as i feel so silly,

How would you change the above unix find statement to use

File::Find

Previous Thread | Next Thread
Test Your Knowledge in Computers #447
Difficulty: Medium
DebianDog is also Puppy Linux.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX date fuction - how to deduct days from today's date

Hi, One of my Unix scripts needs to look for files coming in on Fridays. This script runs on Mondays. $date +"%y%m%d" will give me today's date. How can I get previous Friday's date.. can I do "today's date minus 3 days" to get Friday's date? If not, then any other way?? Name of the files is... (4 Replies)
Discussion started by: juzz4fun
4 Replies

2. Shell Programming and Scripting

Perl copy vs system cp

What are the pros & cons, if any, between using Perl's copy module vs OS's system cp, for copying a file to another directory? Or are they exactly the same? 1) Perl's File::Copy module, as in copy ($filename, $dest_path) or die "ERROR: Cannot copy\n"; 2) if (system ("cp $filename,... (3 Replies)
Discussion started by: slchin
3 Replies

3. Shell Programming and Scripting

System variables in Perl

Hi I'm new to Perl and the forum. I've done a quick search on my question but I didn't see an answer. I sincerely apologize if this question has been asked. I'm trying to have my perl scrip recognize system variable $USER such that: my $test_path = "/temp/\$USER/g03/Gau-11097.EIn"; open... (2 Replies)
Discussion started by: jhbamboo
2 Replies

4. Shell Programming and Scripting

Perl variables in exec or system

I am new in Perl. I am working in simple script and the varibles are working well outside the exec or system command. but they don't work as parameters to exec or system command. The script is attached. please help. (8 Replies)
Discussion started by: ahmed_zaher
8 Replies

5. Shell Programming and Scripting

fuction return in perl

Hi All, I have a perl script(1.pl) that calls a c function defined in another file sample.c #!/usr/bin/perl my $re = 1; my @s = `/home/PERL_SCRIPTING/Rough/sample pline $re 10`; print "$_" foreach(@s); The sample.c is as bwlow: # include <stdio.h> int pline(int, int);... (4 Replies)
Discussion started by: jisha
4 Replies

6. UNIX for Advanced & Expert Users

awk and fuction (recursion) !! Urgent !!

Hey all, :D Could you please check following way of writing awk is correct or not ??? ----------------------------------------------------------- ----------------------------------------------------------------- Its recursion being called. tempgrep.txt has : 462948 1311040 880922... (12 Replies)
Discussion started by: varungupta
12 Replies

7. Shell Programming and Scripting

Need Help w/PERL system command

Hi, I'm wanting to run an nslookup, dig or whatever to check for the existence of a printer. The PERL script will display the results on the screen, but I can't figure out how to capture the result & test the value. Any ideas will be greatly appreciated!!! Thank You (1 Reply)
Discussion started by: lorik
1 Replies

8. Programming

about memset fuction

Dear all, In my code,i am planning to use memset function to re-initialise an array before populating it everytime. Will using memset function be an overload to the program? (3 Replies)
Discussion started by: ranj@chn
3 Replies

9. Shell Programming and Scripting

perl - system command

Can this be done without using te system command? I have a directory with a large number of files in it, but I am interested in only the 8 most recent. The directory looks like -rw-rw-rw- 1 adsm adsm 13412 Sep 22 08:31 events_dump_09222005.csv.gz -rw-rw-rw- 1 adsm adsm ... (5 Replies)
Discussion started by: reggiej
5 Replies

10. UNIX for Dummies Questions & Answers

Get Oracle fuction return value in a variable

Hi All, :confused: I have the following code. var=' ' sqlplus user/pass@DB <<EOF whenever sqlerror exit 1 select package.func() into $var from dual; EOF echo $var But, this code does not work to display the value returned by the oracle function. Do we have to bind variables before... (3 Replies)
Discussion started by: rahulrathod
3 Replies

Featured Tech Videos