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 = 87d380e1881d226c
Timestamp =
#!/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;
$fn
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/\s+$//
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 filehandle and back in
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
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-memory string
as a file:
##
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
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
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
Hi,
The line -- my %test = my($fname, $fvalu)=split(/=/, $test);
Will insert only two elements into %test.
Try:
my %test = split (/=/,$test);
Yaron Kahanovitch
- Original Message -
From: Goksie [EMAIL PROTECTED]
To: Perl Beginners beginners@perl.org
Sent: Sunday, April 29, 2007
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
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/perl
use
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
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
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)
Edward Wijaya wrote:
my @AoH = (
{ values = ['AGCAG','AGCCG','AGCCGGGCG','AGCCAGGAG'] },
{ values = ['AGCGGAGCG','AGCCGAGGG','AGCGGAGGG'] },
);
for ( 0..$#AoH ) {
$AoH[$_]-{ic} = compute_ic( @{ $AoH[$_]-{values} } );
}
print Dumper @AoH;
Thanks Gunnar,
I managed to
What have you done to find out?
perldoc -f sort
perldoc -q sort an array
I think you also need to read up on data structures:
perldoc perldsc
Gunnar,
It works!
I can't express enough my gratitude for your
help and patience.
I apologize for having trouble you this far.
Actually I
Edward Wijaya wrote:
Thanks so much for your reply Gunnar,
The purpose is as follows.
For example these lines:
AGCAG,AGCCG,AGCCGGGCG,AGCCAGGAG 15.188721875540
AGCGGAGCG,AGCCGAGGG,AGCGGAGGG 16.163408331891
\_/ \_/
@Array1
Thanks so much for your reply Gunnar.
However there is a bit complication.
I just realize that hash table can only
return the values of unique key.
Please try to execute the code below along
with the attached file, and the target answer below for clarity,
(the current code return the deviated
Edward Wijaya wrote:
I just realize that hash table can only return the values of
unique key.
And the compute_ic() function computes numbers that are not unique,
so they can't be hash keys, I see. You have a new problem.
We don't know much about the bigger picture here. Would possibly an
array of
my @AoH = (
{ values = ['AGCAG','AGCCG','AGCCGGGCG','AGCCAGGAG'] },
{ values = ['AGCGGAGCG','AGCCGAGGG','AGCGGAGGG'] },
);
for ( 0..$#AoH ) {
$AoH[$_]-{ic} = compute_ic( @{ $AoH[$_]-{values} } );
}
print Dumper @AoH;
Thanks Gunnar,
I managed to construct the Array of Hashes
Edward Wijaya wrote:
Is there anyway in Perl to create hash with multiple key for an
array?
Yes.
my %HoA = ( key1 = [ @array1 ] );
$HoA{key2} = $HoA{key1};
The purpose is as follows.
For example these lines:
AGCAG,AGCCG,AGCCGGGCG,AGCCAGGAG 15.188721875540
Thanks so much for your reply Gunnar,
The purpose is as follows.
For example these lines:
AGCAG,AGCCG,AGCCGGGCG,AGCCAGGAG 15.188721875540
AGCGGAGCG,AGCCGAGGG,AGCGGAGGG 16.163408331891
\_/ \_/
@Array1
Why not something like this?
my %hash;
while(SM_FILE){
chomp $_;#remove the newline
my($key,$value) = split(/,/,$_); #split by commas or whatever
$hash{$key} = $value;#assign the value here
}
foreach(sort keys %hash){
print $key = $value\n;
}
-Original Message-
From: Jamie Risk [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 30, 2003 9:32 AM
To: [EMAIL PROTECTED]
Subject: creating hash from name/value found in file.
Okay, it's 5:25pm and I started programming PERL shortly
after downloading
the 5.8.0 tarballs
Thanks, Timothy, I almost had it before I decided to look back at the list.
My only concern was the creation of data space for each new key, I guess
it's a non issue. ALTHOUGH, if I have repetitions of keys, code below would
obliterate previous key data, would it not? I guess I'm looking at a hash
PROTECTED]]
Sent: Wednesday, January 29, 2003 3:03 PM
To: [EMAIL PROTECTED]
Subject: Re: creating hash from name/value found in file.
Thanks, Timothy, I almost had it before I decided to look back at the list.
My only concern was the creation of data space for each new key, I guess
it's a non issue
Jamie Risk wrote:
Okay, it's 5:25pm and I started programming PERL shortly after downloading
the 5.8.0 tarballs at 2:30pm.
I'd like to create a hash from a text file that has name/value pairs, one
per line. So far, I'm only capable of reading it in as a list - this PERL
stuff really seems
Original Message-
From: Jamie Risk [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 29, 2003 3:03 PM
To: [EMAIL PROTECTED]
Subject: Re: creating hash from name/value found in file.
Thanks, Timothy, I almost had it before I decided to look back at the
list.
My only concern was the
On Mon, 30 Sep 2002, Paul and Joann Van Dalen wrote:
Hi all,
Given an input file that has the following records:
123ABCXX112Zz
123DEFXX113Z
123EEFXX112 Zz
444cccvvbfdc
444
open(FILE, yourfile) or die can't open $!;
my(%LINES);
while(FILE){
my($key) = split;
$LINES{$key) = $_ unless exists $LINES{$key);
}
close FILE;
# %LINES now has key value pairs of '123' and '444' as the keys and the
value is the first occurence in the file.
-Original
Hi Paul,
Ihashes would need a little bit of work to work with this, as you will have
multiple entries with the same key, eg you have three lines beginning 123.
if you have all you lines in an array, you could do this:
foreach $line (sort @arry) {
die Invalid input: $line\n unless ($line
and just so you don't try to load any blank lines into the hash and get an
error, throw in a check for blank lines
open (INPUTFILE, $your_input_file) or die Error opening
$your_input_file: $!\n;
my %uniq_hash;
while (INPUTFILE) {
next if /^$/; ## SKIP BLANKS
(my
On Tue, 1 Oct 2002, Kipp, James wrote:
and just so you don't try to load any blank lines into the hash and get an
error, throw in a check for blank lines
open (INPUTFILE, $your_input_file) or die Error opening
$your_input_file: $!\n;
my %uniq_hash;
while (INPUTFILE) {
next if /^$/; ## SKIP BLANKS
should have done that check, thanks for the correction
Actually Nikola's version saves us from needing this check by throwing in
the unless line :-)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Paul And Joann Van Dalen wrote:
Hi all,
Given an input file that has the following records:
123ABCXX112Zz
123DEFXX113Z
123EEFXX112 Zz
444cccvvbfdc
444CCdvvbfd
Paul And Joann Van Dalen wrote:
Hi all,
Given an input file that has the following records:
123ABCXX112Zz
123DEFXX113Z
123EEFXX112 Zz
444cccvvbfdc
444CCdvvbfd
37 matches
Mail list logo