"David Van Ginneken" schreef:
> $fn =~ s/^\s*//g;
> $fn =~ s/\s*$//g;
> $val =~ s/^\s*"?//g if defined $val;
> $val =~ s/"?\s*//g if defined $val;
The g-modifiers and the * quantifiers and the "? are either not right or
not necessary.
Alternative:
s/^\s+//, s
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
$/ = "\n\n"; # Specify the record separator as 2 new lines..
my $fn = 'detail-20070423_1.txt';
open my $fh, '<', $fn or die $!;
while(<$fh>){
my %test;
map {
my ($fn,$val) = split(/=/,$_,2);
$fn =~ s/^\s*//g;
Matthew J. Avitable wrote:
> Unf. Got the picture! I'll spend my night in the stockades :)
>
> -m
>
> Rob Dixon wrote:
>> Matthew J. Avitable wrote:
>>>
>>> Given the original string ...
my $test =
'NAS-IP-Address = 192.168.42.1
...
Acct-Unique-Session-Id = "87d380e1
Unf. Got the picture! I'll spend my night in the stockades :)
-m
Rob Dixon wrote:
Matthew J. Avitable wrote:
Given the original string ...
my $test =
'NAS-IP-Address = 192.168.42.1
...
Acct-Unique-Session-Id = "87d380e1881d226c"
Timestamp = 1177282824';
You could also invoke
Rob Dixon wrote:
> Matthew J. Avitable wrote:
>>
>> Given the original string ...
>>> my $test =
>>> 'NAS-IP-Address = 192.168.42.1
>>> ...
>>> Acct-Unique-Session-Id = "87d380e1881d226c"
>>> Timestamp = 1177282824';
>>>
>>
>> You could also invoke perl 5.8's ability to treat an in-memo
Matthew J. Avitable wrote:
Given the original string ...
my $test =
'NAS-IP-Address = 192.168.42.1
...
Acct-Unique-Session-Id = "87d380e1881d226c"
Timestamp = 1177282824';
You could also invoke perl 5.8's ability to treat an in-memory string as
a file:
## get a filehandle on $
> ""Matthew" == "Matthew J Avitable" <[EMAIL PROTECTED]> writes:
"Matthew> You could also invoke perl 5.8's ability to treat an in-memory string
as a
"Matthew> file:
You can, but that's rapidly sliding into "obfuscation" territory. You already
have the data... why shove it out as a filehand
Given the original string ...
my $test =
'NAS-IP-Address = 192.168.42.1
...
Acct-Unique-Session-Id = "87d380e1881d226c"
Timestamp = 1177282824';
You could also invoke perl 5.8's ability to treat an in-memory string as
a file:
## get a filehandle on $test
open(my $fh, '<', \$test
Rodrick Brown wrote:
use Data::Dumper;
my %h;
map { $h{$_->[0]}=$_->[1] } map { [ split/=/,$_ ] } split/\n/,$test;
print Dumper(\%h);
Or, more intelligibly,
my %h;
foreach (split /\n/, $test) {
my ($key, $val) = split /=/;
$h{$key} = $val;
}
Rob
--
To unsubscribe, e-mail: [EMAIL P
On 4/29/07, Goksie <[EMAIL PROTECTED]> wrote:
hello,
Can someone help me correct this code.
if i print, it only print the first line.
Goksie
#!/usr/bin/perl
use strict;
my $test =
'NAS-IP-Address = 192.168.42.1
Quintum-NAS-Port = "0 0/0/c1dc2a26"
NAS-Port-Type = Async
Use
hello,
Can someone help me correct this code.
if i print, it only print the first line.
Goksie
#!/usr/bin/perl
use strict;
my $test =
'NAS-IP-Address = 192.168.42.1
Quintum-NAS-Port = "0 0/0/c1dc2a26"
NAS-Port-Type = Async
User-Name = "192.168.42.8"
Called-Station-Id =
Hi,
if you're reading a config file to get the string maybe Config::General is
handy.
HTH
Martin
On Sun, 29 Apr 2007 14:27:52 +0100
Goksie <[EMAIL PROTECTED]> wrote:
> hello,
>
> Can someone help me correct this code.
>
> if i print, it only print the first line.
>
> Goksie
>
> #!/usr/bin
Goksie wrote:
hello,
Can someone help me correct this code.
if i print, it only print the first line.
Goksie
#!/usr/bin/perl
use strict;
my $test =
'NAS-IP-Address = 192.168.42.1
Quintum-NAS-Port = "0 0/0/c1dc2a26"
NAS-Port-Type = Async
User-Name = "192.168.42.8"
Call
pril 29, 2007 4:27:52 PM (GMT+0200) Auto-Detected
Subject: creating hash from scalar variable
hello,
Can someone help me correct this code.
if i print, it only print the first line.
Goksie
#!/usr/bin/perl
use strict;
my $test =
'NAS-IP-Address = 192.168.42.1
Quintum-NAS-Port =
I think something like this would work for you.
my %test;
map { my ($fn,$val) = split(/=/,$_,2); $test{$fn}=$val;} split(/\n/, $test);
I noticed some of your values had equal signs in them, so in the inside
split, I also specified you wanted 2 values so that you receive the full
expected value b
Hi there,
Your problem here is that perl is kind enough to see the whole scalar as one
line. So what you would have to do is break it up in several linse shove
them in an array. Then do a foreach on the array to split and drop it in the
hash like so:
my @array = split( /\n/, $test );
foreach m
hello,
Can someone help me correct this code.
if i print, it only print the first line.
Goksie
#!/usr/bin/perl
use strict;
my $test =
'NAS-IP-Address = 192.168.42.1
Quintum-NAS-Port = "0 0/0/c1dc2a26"
NAS-Port-Type = Async
User-Name = "192.168.42.8"
Called-Station-Id =
17 matches
Mail list logo