Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Extract values from Perl variable

Shell Programming and Scripting


Tags
awk, perl

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-29-2012   -   Original Discussion by prashant2507198
prashant2507198 prashant2507198 is offline
Registered User
 
Join Date: May 2010
Last Activity: 25 October 2013, 5:03 AM EDT
Posts: 46
Thanks: 1
Thanked 1 Time in 1 Post
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..
Sponsored Links
    #2  
Old Unix and Linux 12-29-2012   -   Original Discussion by prashant2507198
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 19 November 2017, 7:33 PM EST
Location: NM
Posts: 11,239
Thanks: 571
Thanked 1,116 Times in 1,030 Posts
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.
Sponsored Links
    #3  
Old Unix and Linux 12-29-2012   -   Original Discussion by prashant2507198
prashant2507198 prashant2507198 is offline
Registered User
 
Join Date: May 2010
Last Activity: 25 October 2013, 5:03 AM EDT
Posts: 46
Thanks: 1
Thanked 1 Time in 1 Post
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 Unix and Linux 12-31-2012   -   Original Discussion by prashant2507198
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 8 November 2017, 2:32 AM EST
Location: India
Posts: 1,976
Thanks: 31
Thanked 574 Times in 547 Posts

Code:
#! /usr/bin/perl -w
use strict;

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

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

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
substitute variable for values in perl cesarNZ Shell Programming and Scripting 1 01-24-2011 08:22 PM
extract key values migurus Shell Programming and Scripting 4 08-06-2010 07:12 AM
perl-extract data from hash values userscript Shell Programming and Scripting 1 01-17-2010 09:18 PM
extract values from column with Perl m_elena Shell Programming and Scripting 6 10-25-2009 08:00 AM
How to store values into variable in perl chittiprasad15 Linux 3 05-08-2008 01:21 AM



All times are GMT -4. The time now is 10:14 PM.