in reply to Re: Need help to convert short c shell script to perl
in thread Need help to convert short c shell script to perl
Not quite true. Here is an experiment I did:
Given a file to be sourced in like this:
Here is how I sourced it in:VAR1="FOO" VAR2="FEE" VAR3="FUM" export VAR1 export VAR2 export VAR3
It ain't pretty but it works. Here is a truncated version of the results:#!/usr/bin/perl -w use strict; use Data::Dumper; my %envstuff=source_in("source.sh"); print Dumper(\%envstuff); sub source_in { my $fname=shift; my @vars=(); open RIPIT,sprintf("(. $fname ; env) | ",$fname) or die $fname . $ +!; while(my $line=<RIPIT>){ chomp $line; my ($key,$val)=split("=",$line); push @vars,$key,$val; } close RIPIT; return @vars; }
I'm sure there is more than one way to get this done and I'll be some of them are quite elegant, but sometimes I like to just pull a hammer out of the toolbox and whack nails that stick out.$VAR1 = { 'VAR1' => 'FOO', 'VAR2' => 'FEE', 'VAR3' => 'FUM',
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Need help to convert short c shell script to perl
by Tux (Canon) on Sep 25, 2007 at 15:30 UTC | |
by blue_cowdawg (Monsignor) on Sep 25, 2007 at 15:49 UTC | |
by cdarke (Prior) on Sep 27, 2007 at 09:43 UTC | |
by blue_cowdawg (Monsignor) on Sep 27, 2007 at 13:52 UTC |