Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 4th, 2009, 10:22 PM
umbrella's Avatar
umbrella umbrella is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 79 umbrella User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 10 m 10 sec
Reputation Power: 2
Perl system $ variables

hi every1,
I need suggestion how interpolate variable($ip) to sysetm() or exec()?
I tried different ways, but it doesn't add address.
Code:
my $ip ='10.10.10.10'
exec q( /usr/bin/perl -p -i -e 's/^external_addr.*$/external_addr=$ip/g' /etc/pf.conf) ;
system q(/usr/bin/perl -p -i -e 's/^external_addr.*$/external_addr="$ip"/g' /etc/pf.conf);

Reply With Quote
  #2  
Old July 4th, 2009, 11:25 PM
KevinADC's Avatar
KevinADC KevinADC is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2004
Location: Sunny Southern California
Posts: 2,687 KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 12 h 54 m 48 sec
Reputation Power: 857
use qq (double-quoted string) instead of q (single-quoted string)

Reply With Quote
  #3  
Old July 5th, 2009, 06:19 AM
umbrella's Avatar
umbrella umbrella is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 79 umbrella User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 10 m 10 sec
Reputation Power: 2
I tried this before, but received error
Substitution replacement not terminated at -e line 2

exec qq( /usr/bin/perl -p -i -e 's/^external_addr.*$/external_addr=$ip/g' /etc/pf.conf) ;

Reply With Quote
  #4  
Old July 5th, 2009, 08:28 AM
OmegaZero OmegaZero is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 288 OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 2 h 53 m 40 sec
Reputation Power: 367
You probably don't want that to interpolate...
Code:
exec qq( /usr/bin/perl -p -i -e 's/^external_addr.*$/external_addr=$ip/g' /etc/pf.conf) ;



(Incidentally, why start a new perl process instead of writing the loop in your existing one?)
__________________
sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

Reply With Quote
  #5  
Old July 5th, 2009, 09:42 AM
umbrella's Avatar
umbrella umbrella is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 79 umbrella User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 10 m 10 sec
Reputation Power: 2
Quote:
You probably don't want that to interpolate...

Why? $ - just pointed on end of line and should works quite well. But if I set
s/^external_addr=.*/...so on
it still doesn't.
Quote:
(Incidentally, why start a new perl process instead of writing the loop in your existing one?)

Because I'm too lazy so as to make a new loop =)
I want do that like sed -i, because on different unix-system I've different sed version.

Last edited by umbrella : July 5th, 2009 at 09:49 AM.

Reply With Quote
  #6  
Old July 5th, 2009, 04:54 PM
shawnhcorey's Avatar
shawnhcorey shawnhcorey is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Location: The Great White North
Posts: 60 shawnhcorey User rank is Second Lieutenant (5000 - 10000 Reputation Level)shawnhcorey User rank is Second Lieutenant (5000 - 10000 Reputation Level)shawnhcorey User rank is Second Lieutenant (5000 - 10000 Reputation Level)shawnhcorey User rank is Second Lieutenant (5000 - 10000 Reputation Level)shawnhcorey User rank is Second Lieutenant (5000 - 10000 Reputation Level)shawnhcorey User rank is Second Lieutenant (5000 - 10000 Reputation Level)shawnhcorey User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 12 h 10 m 12 sec
Reputation Power: 77
Quote:
Originally Posted by umbrella
hi every1,
I need suggestion how interpolate variable($ip) to sysetm() or exec()?
I tried different ways, but it doesn't add address.


Use sprintf to construct the string.
Code:
my $ip ='10.10.10.10'
exec sprintf q( /usr/bin/perl -p -i -e 's/^external_addr.*$/external_addr=%s/g' /etc/pf.conf), $ip;
system sprintf q(/usr/bin/perl -p -i -e 's/^external_addr.*$/external_addr="%s"/g' /etc/pf.conf), $ip;

Reply With Quote
  #7  
Old July 5th, 2009, 06:51 PM
OmegaZero OmegaZero is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 288 OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level)OmegaZero User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 2 h 53 m 40 sec
Reputation Power: 367
Quote:
Originally Posted by umbrella
Why? $ - just pointed on end of line and should works quite well. But if I set
s/^external_addr=.*/...so on
it still doesn't.


Trying to be a bit more clear.

The problem is when perl is parsing a quoted string, not when the system()'s perl parses the regex. Perl finds two variables in the string and interpolates the values of those values.
Code:
qq( /usr/bin/perl -p -i -e 's/^external_addr.*$/external_addr=$ip/g' /etc/pf.conf)

You want a literal $/ though, not the value of the record separator so you need to escape the $ and stop it from interpolating.
Comments on this post
KevinADC agrees!

Reply With Quote
  #8  
Old July 5th, 2009, 08:09 PM
Axweildr's Avatar
Axweildr Axweildr is offline
'fie' on me, allege-dly
Dev Shed God 15th Plane (12000 - 12499 posts)
 
Join Date: Mar 2003
Location: in da kitchen ...
Posts: 12,277 Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)Axweildr User rank is General 56th Grade (Above 100000 Reputation Level)  Folding Points: 143856 Folding Title: Super Ultimate Folder - Level 1Folding Points: 143856 Folding Title: Super Ultimate Folder - Level 1Folding Points: 143856 Folding Title: Super Ultimate Folder - Level 1Folding Points: 143856 Folding Title: Super Ultimate Folder - Level 1Folding Points: 143856 Folding Title: Super Ultimate Folder - Level 1Folding Points: 143856 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 1 Week 3 Days 13 h 14 m 41 sec
Reputation Power: 4721
Send a message via Google Talk to Axweildr
Orkut
listen to the man ...
__________________
--Ax
without exception, there is no rule ...
Heavy Haulage Ireland
Targeted Advertising Cookie Optout (TACO) extension for Firefox
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
-- Jamie Zawinski
Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Perl system $ variables


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
Stay green...Green IT