Programming :: Assigning Output Of A Command To An Array In Perl?

Nov 25, 2010

I am trying to execute a Unix Command in perl and assigning its output to an array:

Code:
@File_List=exec("ls -1 /tmp");
but it is not working. I have tried the perl function system() also but its return code is

[code]...

View 10 Replies


ADVERTISEMENT

Programming :: Creating Array From Command Output (Bash Shell Script)

Jan 26, 2011

I have a command that outputs n lines of text, and I want to place each line into an array element, but I can't seem to get the syntax correct

So my command is this:
cat $configfile | sed -n '/cluster:'$clustername'/,/cluster/ p' | awk /host/

Which produces many lines depending on the value of $clustername. I'd like to get each line as elements of an array.

View 5 Replies View Related

Programming :: Perl Array Last 2 Elements Will Not Pop?

Apr 27, 2010

created this array and the last two elements will not pop - phil and sylvia never get up to bat.

1#!/usr/bin/perl
2use strict;
3use warnings;

[code]...

View 3 Replies View Related

Programming :: Check If An Array Is Empty In Perl?

Nov 28, 2008

To do this, can I do this?:

if (@ary = ""),

or is something more needed?

View 4 Replies View Related

Programming :: Passing Array From One Perl Script To Another?

Dec 14, 2010

How do I pass an array from one perl script to another .. also how to read it in another script ?I tried below -

Script 1 - sender program
system ("./program2.pl @array1 @array2");
printf("

[code]...

View 2 Replies View Related

Programming :: Perl Pushing Two Dimensional Array

Apr 22, 2011

I tried to look for this, but there are so little of perl on internet:
Code:
@array = [$title, $description, $pubDate, $link];
push(@feeds1, $array);

I am trying to create a 2 D array by PUSH, so the output would look like:
([ $title, $description, $pubDate, $link ], [ $title, $description, $pubDate, $link ], [ $title, $description, $pubDate, $link ], [ $title, $description, $pubDate, $link ]...etc )

View 2 Replies View Related

Programming :: Perl - Regex With Array Elements?

Mar 13, 2011

I have .txt.gz files that store queries made on a browser, d my job is to analyze them.The information is stored in a xml-like style.Quote:

<browser>lwp-trivial/1.41</browser>
<http_code>200</http_code>
<keywords />

[code]...

View 6 Replies View Related

Programming :: Split Fields In A Perl Array?

Dec 16, 2010

I have an array called @logons. How can I step thru the array and split the fields? This is what I have so far, but doesnt work. I got the feeling I the split statement syntax is incorrect.

Code:

print @logons;
foreach my $logons(@logons){
($userid, $ip) = split(',',$logons);

[code]....

Update: Appears the data in @logons has a column header from the mysql query which I used to populate it with. So that code which I was testing does indeed work.

View 10 Replies View Related

Programming :: Count Occurrency Of Each Array Element - Perl?

May 10, 2010

Exist it a perl function to count how much each array element is into array?

View 14 Replies View Related

Programming :: Restrict The Perl Array Maximum Size?

Feb 9, 2010

How to restrict the maximum size of an array variable in perl such that Ishould not be able to have array elements beyond the maximum size?

View 7 Replies View Related

Programming :: Perl - Stop Range Search At End Of An Array?

Dec 7, 2010

I have data that looks similar to this -

Quote:

John Smith (Address)
123 Main St
Unit 1

[code].....

So I need everything between each name, but I am not guaranteed that each time I match a name that I will have the same amount of lines, so I do a range pattern search line this to get all lines, no matter if there is 5 or 10 or 15. I simply do a loop that goes through the whole array until I hit the match, and this is my search pattern.

Code:

if ($LINE =~ /^s+$SELECTED_NAME/ ... $LINE =~ /(Address)/) {
push @ADDRESS_INFO, $LINE;
}

This works perfectly... until I hit the end and it doesn't get its final pattern match because it's at the end and there is no next entry with a (Address) line. So as a 'hack', I ended up inserting a final scalar at the end of the array that just says (Address) so it knows it's at the end. Ideally though, I'd like to do an "or" statement that says search for Address || return true if I hit the end of the array. How would I match on "End Of Array" essentially?

View 1 Replies View Related

Programming :: Assigning Bash Variable With The System Command In Awk?

Mar 1, 2011

I am having all sorts of trouble trying to assign a variable within an awk script with the system command. I know there is a lot of ways around this problem, but for efficiency reasons, I would like to, within my awk script, do something like

system(x=3)

or

system(x=NR)

and, latter on the shell script which calls the awk script, use the variable $x. But nothing is passed to x. I have already tried things like

command = "x=3"
system(command)

and also used a pipeline within the system to pipe it to /bin/sh In fact tried a lot of stuff like that, using $(( )) etc etc etc I can create directories e write to files (yes, i could write to a file and read from there, but I dont think it is efficient, plus I am puzzled).

View 7 Replies View Related

Programming :: Perl - Store And Access An Array In A Hash Of Hashes?

Jul 7, 2010

I am in need of some syntax help. I'm trying to figure out how to store and retrieve an array out of a hash of hashes. For this example, I'm trying to access the city list for a particular state for a particular country. I understand I could do a join and split on the hash key to combine Country and State, but trying to keep things separated.The code I have gets in all the information for the Countries, and states, and gets the list of cities together, no problem. I store all the city names in an array, then make an anonymous pointer to the array for the hash, like this - $MY_CITIES{$COUNTRY}{$STATE} = [@CITIES]I believe that syntax is correct, or is it? What I'd like to do is I need to cycle through every hash to find if a city exists or not. If it exists in 3 states, then it should print 3 times. Here is the code block to search -

Code:
for $COUNTRY (@LIST_OF_COUNTRIES) {
for $STATE ( keys %MY_CITIES{$COUNTRY){$STATE} ) {

[code]...

View 4 Replies View Related

Programming :: Perl Beginner - Can't Get PerlMagick To Read Filename From Array Element?

Aug 21, 2010

it's been a while since I logged on here! I've been trying my hand at a little perl and have hit a brick wall.I'm using the Imagemagick module to manipulate some images. I can get the following to work without issue:

Code:
$teampath = "/var/www/team1";
$player=Image::Magick->new;

[code]...

View 1 Replies View Related

Programming :: Perl's Foreach Loop Can't Use An Array Element As The Control Variable?

Jul 22, 2011

I'm reading "OReilly Learning Perl 5th Edition", and there are such words:Code:You can use an array element like $fred[2] in every place? where you could use any other scalavariable like $fred.At the bottom of the page, it explains the ? like this:Code:The most notable exception is that the control variable of a foreach loop, which you?ll see later in this chapter, must be a simple scalar.Since Perl has the save-and-restore mechanism for the control variable, why an array element can't be used as the control variable

View 1 Replies View Related

Programming :: C Program To Get Input Of Array And Output It

Aug 14, 2010

I am creating a 15 integer array which is input from the user and outputted for the.

Ex.
Enter the array values: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Your values are: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Code:

View 4 Replies View Related

Programming :: Output Coming In New Line In Perl?

Feb 22, 2010

Here is some line I have written in perl to show my name :

[code]...

And after stdin kumar, its giving the output as

[code]...

output should be [code]... but why its coming in two lines?

View 2 Replies View Related

Programming :: Send A Mysql Query Output Into An Array?

Jul 27, 2010

i will be quick, im trying to send a mysql query output into an array ie:

Code:
declare -a HD
HD=`echo "USE db; SELECT uid FROM user" | mysql -u $login -p$pwd -h $dbhost -B`
echo ${#HD}
those vars in mysql connection are previously and correctly assigned.
but got an error

script.sh: 2: declare: not found

View 3 Replies View Related

Programming :: Nested Loop Using A Counter To Increment Array Output?

Feb 2, 2011

I work in a simulations environment. I'm trying to write a bash script that will read fields from a .csv file into an array, the first field being an identifiyng number and the second field being a corresponding url. There are about 1600 of these number/url combinations in the .csv file that i'm reading from. Once that is done i want it to parse a text file and match the number, when it has a match i want it to enter the corresponding url into a particular line in the text file. The script I have written (with the help of the people on this forum a while back) does this well, but now I have a lot more data to parse. I think the script itself is explanatory enough to see what i'm doing. What i would like to do is cut it down to one while loop nested inside another loop so that I don't have 1600 or so elif statements. I can't figure out how to increment the output of the array. for instance, the first cycle would find the number that matches ${record1[2]} and input the url stored in ${record1[3]}. the next cycle would match ${record1[4]} and input the url in ${record1[5]}, and so on, does that make sense? The code is below and a sample .csv and text file are attached.

[Code]...

View 14 Replies View Related

Programming :: Perl Script Output Can't Be Redirected To A File / Sort It?

Feb 18, 2010

The perl script I wrote works fine if I print the result to screen
x0_amber.pl 1 1000 0 5

But whenever I want to output to a file with
x0_amber.pl 1 1000 0 5 > x0_out

it never really prints out to the file.

It worked earlier, but I was playing with my PATH lately, I don't know if it's related to that

View 7 Replies View Related

Programming :: Use Regex In Perl Script To Detect Allowed Words From The File And Then Print Output To The Screen?

Oct 4, 2010

Its my first post in here so please be patient I am trying to use regex in perl script to detect allowed words from the file and then print output to the screen.

As an example : I have text file with orders and returns :

Item2-SKU-2-11.08.2010-online
Item3-SKU-3-11.09.2010-return
Item4-SKU-4-11.09.2010-store

My question: is it possible to make sure that i am ony outputing to the screen orders based on few conditions like Item,order form e.g. online.And is it possible to have multiple matches (Item2 only diplay if ordered online etc)

View 1 Replies View Related

General :: Sed: Assigning Its Output To A Variable?

Feb 3, 2011

Kernel 2.6.21.5, GNU/Linux (Slackware 12.0).In this script,

Code:
semoi@darkstar:~$ cat rename4.sh
#!/bin/bash
INPUT="k3b_audio_0_04"

[code]...

View 3 Replies View Related

Programming :: Show The Output Of Shell Command Into A Textbox, Ex Ps -efc Command?

Oct 20, 2010

I am using gtk to program GUI. How can I show the output of shell command into a textbox, ex ps -efc command ?

View 3 Replies View Related

Programming :: Calling A System Command In Perl?

May 20, 2010

I'm trying to call a system command in perl and am having an issue with it.

Here's an example of a command i'd like to call: Code: sed -i '4 c192.168.1.4 www.something.com' hosts this is the section in my perl script where I create the variable and call it: Code: $doit = `sed -i '$line c$ip $host hosts'`system($doit); The $line, $ip, and $host variables are working fine becasue I can replace that section with "prints" and they come out fine. I imagine the problem is where I am creating the $doit variable.

View 7 Replies View Related

Programming :: Declare An Associative Array On The Command Line?

Apr 19, 2011

I am trying to declare an associative array on the command line. I get the following error, could somebody explain this and reslove

$ declare -A score_array
-bash: declare: -A: invalid option

View 1 Replies View Related

Programming :: Sed Bash Command - Not Print Backslash In Perl

Jul 11, 2010

This pretend to be a script for rename a lot of files automatically. So I put the list of files in an array named @lista. But, as you can see, at the end of the command I use a sed filter to print out a backslash for those files that have spaces in their names, so the path for those files could be rightly interpreted.

But there's no way I could print a backslash. It works well when I use the Perl's sed substitution s///, but I need every path in the array to be fixed.

I'd like to add that the bash command works perfectly well alone. I mean outside the Perl script.

This is de command line with the sed filter:

Code:

And this is what it brings:

Code:

View 12 Replies View Related

Programming :: 32512 Error Code In Perl When Trying To Run Shell Command?

Nov 29, 2010

when I execute the command from the shell command line - it works and no error code.if I do the exact same command from a perl file - it fails with code 32512.the file is created from the same perl script that runs the command that fails. file permission is 0664.

Code:
#! /usr/local/pkg/perl-5.8.8/bin/perl
print "Content-type: text/html

[code]...

View 3 Replies View Related

Programming :: Perl - Can't Use String ("html") As An ARRAY Ref While "strict Refs"?

Aug 8, 2009

The below snippet works fine until I use strict. Then it dies with the following error: uote:Can't use string ("html") as an ARRAY ref while "strict refs" in use at ./filetest3 line 18.I want to create @lists based on the $scalars in @type. However, "my @$ext = ()"; and push (@$ext, @files); do not play nice with strict. How do I get around this?Quote:

#!/usr/bin/perl -w
system clear;
use strict;

[code]...

View 9 Replies View Related

Programming :: Perl - Way To Encrypt Command-line Input When User Enter A Password ?

Nov 4, 2010

I need user to input a password through command line in Windows cmd prompt. Is there a way to encrypt the input (such as put it into ......) when user is typing ?

View 2 Replies View Related

Programming :: Find And Replace A String In A File Using Perl Command From Bash Script?

Feb 14, 2011

I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.

perl -pi -e "s/$findstring/$replacestring/" testfile
where as $findstring = print F_WC_TMP"$line
";
and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line
";

But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved