The UNIX and Linux Forums  

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
Pass perl variable to sed hi_ryo Shell Programming and Scripting 4 07-14-2008 11:16 AM
How do I pass a variable to awk? eja UNIX for Dummies Questions & Answers 12 04-03-2007 06:46 PM
How to pass a variable to Awk ? Raynon Shell Programming and Scripting 24 02-26-2007 09:25 AM
pass variable to awk inquirer UNIX for Dummies Questions & Answers 4 02-11-2004 03:23 AM
Pass variable to sed? kristy Shell Programming and Scripting 2 04-04-2002 04:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-18-2007
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Pass csh variable to Perl

Hi All,

I am trying to put the csh variable into a perl.
In the below case, i am trying to put the csh variable "var" into my perl code. I tried to use '"$var"' but i don;t think it works.

Can anybody help me pls?


Code:
#!/bin/csh

set var = `echo "xxx"`

perl myperlcode.pl file

where the perl code is


Code:
#!/usr/local/bin/perl
$[ = 1;                 # set array base to 1
$, = ' ';               # set output field separator
$\ = "\n";              # set output record separator

line: while (<>) {
    chomp;      # strip record separator
    @Fld = split(' ', $_, 9999);
    if ($Fld[1] eq '**' && $Fld[8] eq '2007' && $Fld[2] =~ /'"$var"'/) {
        print $_;
            }

Input File:

ddddd
ppp
** xxx qqqqq qqq qq qq qq 2007
jjjj
kkkk
lll
ppp



Expected Output:
** xxx qqqqq qqq qq qq qq 2007
  #2 (permalink)  
Old 10-18-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Unless you are passing the value as an argument you will most probably have to export it.

Also, in perl try some form of getenv().
  #3 (permalink)  
Old 10-18-2007
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Hi Porter,

Can you explain what is meant by passing by arguement? Any examples?

On the export part , any examples?
  #4 (permalink)  
Old 10-18-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by Raynon View Post
Can you explain what is meant by passing by arguement? Any examples?
just like you did with "file".

Quote:
Originally Posted by Raynon View Post
On the export part , any examples?
apparently "setenv" does the trick.
  #5 (permalink)  
Old 10-18-2007
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
On the Perl side that is

$ENV{'var'}

Of course you have to export it from the shell for Perl to see it.
  #6 (permalink)  
Old 10-18-2007
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Hi cbkihong,

Do you mean the below? I encounter some error though.
I do not know how to export. Can you give me some guidance or show me an example ?


Code:
#!/usr/local/bin/perl
$[ = 1;                 # set array base to 1
$, = ' ';               # set output field separator
$\ = "\n";              # set output record separator

$ENV('var')

line: while (<>) {
    chomp;      # strip record separator
    @Fld = split(' ', $_, 9999);
    if ($Fld[1] eq '**' && $Fld[8] eq '2007' && $Fld[2] =~ /'"$var"'/) {
        print $_;
            }
}

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 10:26 AM.


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