Extract values from Perl variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract values from Perl variable
# 1  
Old 12-29-2012
Extract values from Perl variable

Hi Guys,

I am stuck in a problem.

I have a variable in Perl script which has value for example

Code:
X=a-b-c;

Now, I want to extract a b c separately into different 3 variables. I know this can be done in shell using awk but Perl behaves a bit different.

Can anybody help me on this please?

Thanks in advance,
Prashant

Last edited by jim mcnamara; 12-29-2012 at 10:33 AM..
# 2  
Old 12-29-2012
That example does not appear to be valid perl. What are you trying to do?

If you posted some the actual code, and explained what you wanted you would get better help.
# 3  
Old 12-29-2012
Well, actually I want to extract values from variable.
If we use shell script

Code:
X=a-b-c
Var_a=`echo $X|awk -F"-" '{print $1}'`
Var_b=`echo $X|awk -F"-" '{print $2}'`

So, I want to get the same variable Var_a, Var_b in Perl.

Is it clear now?
# 4  
Old 12-31-2012
Code:
#! /usr/bin/perl -w
use strict;

my $X = "a-b-c";
my @X = split /-/, $X;

foreach (@X) { print "$_\n" }

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to extract values and print at end of each line

In the below perl I am trying to extract and print the values AF1=, the GT value, and F or QUAL diveded by 33 (rounded to the nearest whole #). The GT value is at the end after the GT:PL so all the possibilities are read into a hash h, then depending on the value that is in the line the... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

Extract values

hi I have a line as given below. I need to match "COLUMN_NAME" and get the every third value ie words in between quotes completely (' ') Sample Input - COLUMN_NAME Like '%value%' Or COLUMN_NAME Like '%value%' Or COLUMN_NAME Like '%value value%' Or COLUMN_NAME Like '%value%' OR... (5 Replies)
Discussion started by: Prashanth B
5 Replies

3. Shell Programming and Scripting

Perl :: reading values from Data Dumper reference in Perl

Hi all, I have written a perl code and stored the data into Data structure using Data::Dumper module. But not sure how to retreive the data from the Data::Dumper. Eg. Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies

4. Shell Programming and Scripting

PERL - Variable values getting mixed up!

Hi, I only dip my toe into PERL programming on the odd ocassion so I was wondering if anyone had any ideas as to why the below is happening: When I run my PERL script the variable values seem to get mixed up. my $fileName = basename($maxFile,".TXT"); my $currentSeqNum =... (2 Replies)
Discussion started by: chris01010
2 Replies

5. Shell Programming and Scripting

substitute variable for values in perl

hi all, how do i assign values passed in from command line to and sql statement in perl ?? e.g i want to assign :name1 and :Name2 to be whatever is passed into the perl script command line my $sqlStr = "select * from test_table where column1 = upper(nvl(:name1, name1 )) and column2... (1 Reply)
Discussion started by: cesarNZ
1 Replies

6. Shell Programming and Scripting

perl-extract data from hash values

Hello, I have parsed an xml file using perl to get the hash values and the output looks like this $VAR1 = { 'RT' => { 'List' => { 'String' => ... (1 Reply)
Discussion started by: userscript
1 Replies

7. Shell Programming and Scripting

extract values from column with Perl

Hi everybody I have some problems with PERL programming. I have a file with two columns, both with numeric values. I have to extract the values > 50 from the 2nd columns and sum them among them. The I have to sum the respective values in the first column on the same line and, at the end, I... (6 Replies)
Discussion started by: m_elena
6 Replies

8. Shell Programming and Scripting

Reading variable from file variable values

Hi, Here is the output of lpstat. I would like to read value of Queue which is(abxxxxb1)and status that is DOWN in first line. i dont care what is in second line. any one can help me.thanks Queue Dev Status Job Files User PP % Blks Cp Rnk ------- ----- ---------... (5 Replies)
Discussion started by: sagii
5 Replies

9. Shell Programming and Scripting

perl -write values in a file to @array in perl

Hi can anyone suggest me how to write a file containing values,... say 19 20 21 22 .. 40 to an array @array = (19, 20, ... 40) -- Thanks (27 Replies)
Discussion started by: meghana
27 Replies

10. Linux

How to store values into variable in perl

Hi, Can you please help me of how to store the values into variables. Here is the output in LINUX for the below command. $free output : total used free Mem: 3079276 3059328 19948 Swap: 1023992 6324 1017668 ... (3 Replies)
Discussion started by: chittiprasad15
3 Replies
Login or Register to Ask a Question