Re: Regarding files

2007-05-21 Thread Madan Kumar Nath




Hello,

 Since you are having the whole file in an array.
 1. Keep an index to specify the current line read
 2. Once you found the desired string, you have the index also. So
you can 
 decrement the index and get the lines.

$inex = 0;
foreach $line (@lines) {

$index++;
if($line =~ m/ CHANNEL_INFO_T/)
{
  $prevLine1 = @lines[$index-1];
 $prevLine2 = @lines[$index-2];
}
# do something with $line

}




Hope this helps
Madan


Dharshana Eswaran wrote:
Hi All,
  
  
The below code helps in reading a file in reverse:
  
  
use strict;
  
use warning;
  
  
open( FILE, "$file_to_reverse" )
  
  
or die( "Can't open file file_to_reverse: $!" );
  
  
@lines = reverse FILE;
  
foreach $line (@lines) {
  
# do something with $line
  
}
  
  
But i am trying to grep for a string in the file and once i get the
string,
  
  
I need to read few lines which occurs before the string. For eg:
  
  
typedef union
  
{
  
 TYPE_T type;
  
 MODE_T mode;
  
} CHANNEL_INFO_T;
  
  
Here, I grep for CHANNEL_INFO_T, once i get that, i need to read the
  
elements defined in the union or structure.
  
  
  
I have written a code but i am unable to achieve what i wanted.
  
  
Can anyone guide me in this?
  
  
Thanks and Regards,
  
Dharshana
  
  



-- 

/home/madank/personal/signature.html
Thanx
 Regards
!!

from Madan

Interra Systems India Pvt. Ltd.

A10, Sec9,NOIDA Ph: 0120-2442273/4 Ext 137

visit
my homepage
 









Convert german umlaut to ascii

2007-05-21 Thread Andreas Moroder

Hello,

in our application I have to convert all german Umlaute in a string to a 
two char combination ä to ae, Ö to OE and so on.


Can anyone please tell me how to do this ?

Thanks
Andreas


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Regarding files

2007-05-21 Thread Mumia W.

On 05/20/2007 11:37 PM, Dharshana Eswaran wrote:

Hi All,

The below code helps in reading a file in reverse:

use strict;
use warning;

open( FILE, $file_to_reverse )

 or die( Can't open file file_to_reverse: $! );

@lines = reverse FILE;
foreach $line (@lines) {
 # do something with $line
}

But i am trying to grep for a string in the file and once i get the string,

I need to read few lines which occurs before the string. For eg:

typedef union
{
   TYPE_T type;
  MODE_T mode;
} CHANNEL_INFO_T;

Here, I grep for CHANNEL_INFO_T, once i get that, i need to read the
elements defined in the union or structure.


I have written a code but i am unable to achieve what i wanted.

Can anyone guide me in this?

Thanks and Regards,
Dharshana



You could use Tie::File to treat the file's lines as an array:

use strict;
use warnings;
use Fcntl 'O_RDONLY';
require 'Tie/File.pm';

tie my @file, 'Tie::File', 'anyfile.txt', mode = O_RDONLY
or die(Tie::File failed: $!);

for my $n (0 .. $#file) {
local $\ = \n;
$_ = $file[$n];
if (/CHANNEL_INFO_T/) {
print $file[$n-2];
print $file[$n-1];
print;
}
}

untie @file;







--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Regarding files

2007-05-21 Thread Dharshana Eswaran

Thank you all..

But i dont want to use any perl modules in the code. I am trying to get a
logic without any help from the additional modules.

Thanks and Regards,
Dharshana

On 5/21/07, Mumia W. [EMAIL PROTECTED] wrote:


On 05/20/2007 11:37 PM, Dharshana Eswaran wrote:
 Hi All,

 The below code helps in reading a file in reverse:

 use strict;
 use warning;

 open( FILE, $file_to_reverse )

  or die( Can't open file file_to_reverse: $! );

 @lines = reverse FILE;
 foreach $line (@lines) {
  # do something with $line
 }

 But i am trying to grep for a string in the file and once i get the
string,

 I need to read few lines which occurs before the string. For eg:

 typedef union
 {
TYPE_T type;
   MODE_T mode;
 } CHANNEL_INFO_T;

 Here, I grep for CHANNEL_INFO_T, once i get that, i need to read the
 elements defined in the union or structure.


 I have written a code but i am unable to achieve what i wanted.

 Can anyone guide me in this?

 Thanks and Regards,
 Dharshana


You could use Tie::File to treat the file's lines as an array:

 use strict;
 use warnings;
 use Fcntl 'O_RDONLY';
 require 'Tie/File.pm';

 tie my @file, 'Tie::File', 'anyfile.txt', mode = O_RDONLY
 or die(Tie::File failed: $!);

 for my $n (0 .. $#file) {
 local $\ = \n;
 $_ = $file[$n];
 if (/CHANNEL_INFO_T/) {
 print $file[$n-2];
 print $file[$n-1];
 print;
 }
 }

 untie @file;







--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





Re: [OT] list test (please ignore)

2007-05-21 Thread Dr.Ruud
Tony Heal [EMAIL PROTECTED] wrote:

 Subject: list test (please ignore) 

There are special test lists. Don't test on the real list. 

-- 
Affijn, Ruud

Gewoon is een tijger.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Regarding files

2007-05-21 Thread Dr.Ruud
Dharshana Eswaran schreef:

 i am trying to grep for a string in the file and once i get the
 string, I need to read few lines which occurs before the string.

The classic (state machine) approach is to start storing strings from
the start marker, so typedef union here, and discard the stored lines
when the search string doesn't pop-up. Don't put the file in an array
first.

-- 
Affijn, Ruud

Gewoon is een tijger.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert german umlaut to ascii

2007-05-21 Thread Martin Barth
On Mon, 21 May 2007 08:41:13 +0200
Andreas Moroder [EMAIL PROTECTED] wrote:

 Hello,
 
 in our application I have to convert all german Umlaute in a string to a 
 two char combination ä to ae, Ö to OE and so on.
 
 Can anyone please tell me how to do this ?
 
 Thanks
 Andreas
 
 
for example:

% echo äpfel klöster übelkeit | perl -ple 's/ä/ae/; s/ü/ue/; s/ö/oe/;'
aepfel kloester uebelkeit

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: Convert german umlaut to ascii

2007-05-21 Thread Thomas Bätzler
 
Martin Barth [EMAIL PROTECTED] suggested:

 On Mon, 21 May 2007 08:41:13 +0200
 Andreas Moroder [EMAIL PROTECTED] wrote:
 
  Hello,
  
  in our application I have to convert all german
  Umlaute in a string to 
  a two char combination ä to ae, Ö to OE and so on.
  
  Can anyone please tell me how to do this ?

 for example:
 
 % echo äpfel klöster übelkeit | perl -ple 's/ä/ae/; 
 s/ü/ue/; s/ö/oe/;'
 aepfel kloester uebelkeit

I would suggest you use a hash to map your conversions:

#!/usr/bin/perl -w

use strict;

my %map = ( 'ä' = 'ae', 'Ä' = 'Ae',
'ö' = 'oe', 'Ö' = 'Oe',
'ü' = 'ue', 'Ü' = 'Ue',
'ß' = 'ss' ); # add needed conversions!

my $test = Äpfel Klöster Übelkeit;

my $in =  '[' . join( '', keys %map ) . ']';

$test =~ s/($in)/$map{$1}/eg;

print $test\n;

HTH,
Thomas

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: logic not working

2007-05-21 Thread Celice

Tony Heal wrote:


OK I am probably missing something stupid, but I can not get this to work.
The output should be 'Daily-{day of week)-{MMM}-{DD}-{}' for Sunday
thru Friday and 'Weekly-{1|2|3}-{day of week)-{MMM}-{DD}-{} for
Saturday and every fourth Saturday should start rotating months
'Month-{1|2|3}-{day of week)-{MMM}-{DD}-{}

Anyone got any ideas?

Oh, there is some code at the front that changes the system date from May 1
to 31


Hi Tony

I'm sorry I'm afraid there's so little chance of getting that code working I'm
not even going to try. I spent half an hour trying to understand how it was
structured and what you were trying to do and had to give up. It looks to me
like you've written the whole thing in one go and then started to get it to
work, which isn't the way to go about even simple coding problems: you need to
make software work in small steps at a time and gradually approach the final
solution, all the time with a working partial solution.

To try and get you started here are a few pointers, with most of the code
removed so that the problems are apparent:

You have written

  while ($count lt 532){

my $backupDir = gfsBackup();

sub gfsBackup

}

  $count++;}


which I didn't even know would compile. Take the subroutine out of the while
loop or there's really no point in having it there.

Oh, and it should be

  while ($count  532) {
  }

otherwise you're comparing text instead of numbers.


The lines

  opendir (DIR, $backupBaseDir);
  my @readdir = readdir(DIR);
  closedir(DIR);

  while (@readdir)
  {
  }

are wrong, and the most obvious fix is to put

  foreach (@readdir) {

  }

but I don't know if the code around this will work either way.


You have

  if ( $days[$wday] =~ Saturday )
  {
  }
  elsif ( $days[$wday] =~ Saturday )
  {
  }

which is clearly wrong, and it isn't obvious what you meant. Furthermore these
two conditional lines are indented by different amounts, making me think your
nesting isn't what you think it is. Use less whitespace in your code and
carefully align matching braces.

Finally, stuff like

  if ($days[$wday] =~ Saturday)

should be

  if ($days[$wday] eq 'Saturday')

although this won't actually stop it working.

I think that's all I can do for you for now. Please try to clarify your code
and make it look as if it ought to work before you try it. You are doomed to
failure if you throw together a few approximate source lines and try to hack
them until the output looks right.

Good luck,

Rob


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Regarding files

2007-05-21 Thread Dharshana Eswaran

Keeping the classic (state machine) approach in mid, i tried writing a logic
for the same

But i am not able to retrieve the lines accurately,

Can you please help me with a small piece of code for the same logic which
you mentioned?

On 5/21/07, Dr.Ruud [EMAIL PROTECTED] wrote:


Dharshana Eswaran schreef:

 i am trying to grep for a string in the file and once i get the
 string, I need to read few lines which occurs before the string.

The classic (state machine) approach is to start storing strings from
the start marker, so typedef union here, and discard the stored lines
when the search string doesn't pop-up. Don't put the file in an array
first.

--
Affijn, Ruud

Gewoon is een tijger.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





RE: Regarding files

2007-05-21 Thread Thomas Bätzler
Hi, 

Dharshana Eswaran [EMAIL PROTECTED] wrote:
 Keeping the classic (state machine) approach in mid, i tried 
 writing a logic for the same
 
 But i am not able to retrieve the lines accurately,
 
 Can you please help me with a small piece of code for the 
 same logic which you mentioned?

This example uses an array as a ring buffer to store
previous lines from the input. It'll match lines that
contain the string foobar.

$. contains the number of the current line read from the
last used file handle. This value is in the range of 1..n.

$howmany is the ring buffer size and determines how many
lines of text (including the match) are shown.

Sample usage (assuming you're saving this as linebuf.pl):

$ ./linebuf.pl  linebuf.pl 
   12:   $buf[ $. % $howmany ] = $line;
   13: 
   14:   if( $line =~ m/foobar/ ){

#!/usr/bin/perl -w

use strict;

my @buf;

# number of context lines including matching line
my $howmany = 3;

while( my $line =  ){
  # store current line in ring buffer
  $buf[ $. % $howmany ] = $line;

  if( $line =~ m/foobar/ ){

# if we have a match, retrieve the previous
# lines from the ring buffer.
for( my $i = $howmany - 1; $i = 0; $i-- ){
  # number of the line we're retrieving
  my $lineno = $. - $i;
  # show fewer (or no) context lines for a match
  # near (or at) the start of the input
  next unless $lineno = 1;
  printf %5d: %s, $lineno, $buf[ $lineno % $howmany ];
}
  }
}
__END__

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Unable to store the output of a command

2007-05-21 Thread divya

Hi Andy,

Thanks for the reply.

I tried it out, but still not able to store error msgs.

What does 21 mean?

Is there any other way out.

Thanks,

Divya


Andy Greenwood wrote:


On 5/18/07, divya [EMAIL PROTECTED] wrote:


Hi,

I want to store the output of following command:
vcover merge outfile in1 in2

I tried :
1) @result = `vcover merge outfile in1 in2`;
2) system(vcover merge outfile in1 in2  @result);

I can see some error displays on the screen. But these are not getting
stored in @result.



backticks (``) will direct the STDOUT of the command to the array.
However, your STDERR will not be directed normally. If you want those
errors directed into your array, try something like

@result = `vcover merge outfile in1 in2 21`;



Kindly please suggest some way to store it.

NOTE : script runs on linux m/c

Thanks,
Divya









eInfochips Business Disclaimer:
This message may contain confidential, proprietary or legally Privileged information. In 
case you are not the original intended Recipient of the message, you must not, directly 
or indirectly, use, Disclose, distribute, print, or copy any part of this message and you 
are requested to delete it and inform the sender. Any views expressed in this message are 
those of the individual sender unless otherwise stated. Nothing contained in this message 
shall be construed as an offer or acceptance of any offer by eInfochips Limited and/or 
eInfochips Inc(eInfochips) unless sent with that express intent and with due 
authority of eInfochips. eInfochips has taken enough precautions to prevent the spread of 
viruses. However the company accepts no liability for any damage caused by any virus 
transmitted by this email.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Unable to store the output of a command

2007-05-21 Thread Srinivas

divya wrote:

Hi Andy,

Thanks for the reply.

I tried it out, but still not able to store error msgs.

What does 21 mean?

This means redirecting standard error to standard output.

-srini


Is there any other way out.

Thanks,

Divya


Andy Greenwood wrote:


On 5/18/07, divya [EMAIL PROTECTED] wrote:


Hi,

I want to store the output of following command:
vcover merge outfile in1 in2

I tried :
1) @result = `vcover merge outfile in1 in2`;
2) system(vcover merge outfile in1 in2  @result);

I can see some error displays on the screen. But these are not getting
stored in @result.



backticks (``) will direct the STDOUT of the command to the array.
However, your STDERR will not be directed normally. If you want those
errors directed into your array, try something like

@result = `vcover merge outfile in1 in2 21`;



Kindly please suggest some way to store it.

NOTE : script runs on linux m/c

Thanks,
Divya









eInfochips Business Disclaimer:
This message may contain confidential, proprietary or legally 
Privileged information. In case you are not the original intended 
Recipient of the message, you must not, directly or indirectly, use, 
Disclose, distribute, print, or copy any part of this message and you 
are requested to delete it and inform the sender. Any views expressed 
in this message are those of the individual sender unless otherwise 
stated. Nothing contained in this message shall be construed as an 
offer or acceptance of any offer by eInfochips Limited and/or 
eInfochips Inc(eInfochips) unless sent with that express intent and 
with due authority of eInfochips. eInfochips has taken enough 
precautions to prevent the spread of viruses. However the company 
accepts no liability for any damage caused by any virus transmitted by 
this email.





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: AW: Net::Ping Bug found?

2007-05-21 Thread John W. Krahn
Angerstein wrote:

 Ethereal would do, too.

They've changed the name from Ethereal to Wireshark.



John


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




(was: Regarding files)

2007-05-21 Thread Dr.Ruud
Dharshana Eswaran schreef:

You really shouldn't quote text that is no longer relevant, such as
signatures and mailing list tails.

 Ruud:
 Dharshana Eswaran:

 i am trying to grep for a string in the file and once i get the
 string, I need to read few lines which occurs before the string.

 The classic (state machine) approach is to start storing strings from
 the start marker, so typedef union here, and discard the stored
 lines when the search string doesn't pop-up.

 Can you please help me with a small piece of code for the same logic
 which you mentioned?

#!/usr/bin/perl
  use strict;
  use warnings;

  my $phase = 0;
  my $s;
  while () {
  if(0 == $phase) {
  /^\s*typedef union\s*(?:\{\s*)?$/
and ++$phase and $s = $_;
  }
  elsif (1 == $phase) {
  $s .= $_;
  if (/^\s*}\s*(\w+)\s*;\s*$/) {
  'CHANNEL_INFO_T' eq $1
and ++$phase and last;
  $s = '';
  $phase--;
  }
  }
  else { die ugly phase($phase)}
  }
  $phase == 2 and print $s;
__END__

(untested)


But a real parser would also catch variants such as

typedef union {
TYPE_T type;
   MODE_T mode;
}
CHANNEL_INFO_T;

See also:
http://search.cpan.org/search?query=balancedmode=module

-- 
Affijn, Ruud

Gewoon is een tijger.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Parsing XML data

2007-05-21 Thread Mike Blezien

Hello,

I am working with a XML gateway system which sends back response results in XML 
format. I have been trying to work w/XML::Simple to parse the data, but not too 
much success. This is a sample of the XML response data, the * indicate the 
data we need to extract from XML file. I tried used Data::Dumper to help, but 
didn't get the results I though, any help would be much appreciated as the best 
way to parse this data.


--
EdentifyResponse
 *responsetypesuccess/responsetype
*code100/code
 *message/message
 *transactionidde7556e-4875-8da1-26521e504ec9/transactionid
 response
   idalertresponse
 *fullnameJohn Smith/fullname
 *last4ssn1234/last4ssn
 *locatorLOCATOR/locator
 *datecreatedDATECREATED/datecreated
 *lastscandateLASTSCANDATE/lastscandate
 *riskratingRISKRATING/riskrating
 *confirmsCONFIRMS/confirms
 *chg_confirmsCHG_CONFIRMS/chg_confirms
 *suspectsSUSPECTS/suspects
 *chg_suspectsCHG_SUSPECTS/chg_suspects
 *surnamematchSURNAMEMATCH/surnamematch
 *chg_surnamematchCHG_SURNAMEMATCH/chg_surnamematch
 *differentsurnameDIFFERENTSURNAME/differentsurname
 *chg_differentsurnameCHG_DIFFERENTSURNAME/chg_differentsurname
 *ssnmatchonlySSSMATCHONLY/ssnmatchonly
 *chg_ssnmatchonlyCHG_SSNMATCHONLY/chg_ssnmatchonly
 *riskindicatorsRISHKINDICATORS/riskindicators
   /idalertresponse
 /response
/EdentifyResponse
---


Mike(mickalo)Blezien
===
Thunder Rain Internet Publishing
=== 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Efficient matching

2007-05-21 Thread Karyn Williams
I need to check for strings in a file. An example would be checking for a
username in /etc/passwd or /var/log/maillog. The string is in another file,
sometimes a single field on a line by itself, sometimes in a line with
other strings. Based on what I have seen online and what I have done in
other scripts I can :


1. slurp the file into a single string and then check for a match.

2. read the relevent field from the file into hash keys and check for a
match. 

3. Loop through the file line by line and look for a match. 


Generally there are 1 - 2,000 strings, and 2,000 to 1,500,000 lines per file.

I am wondering how these different methods may impact performance.  

I hope I have been clear. 

TIA.




-- 

Karyn Williams
Network Services Manager
California Institute of the Arts
[EMAIL PROTECTED]
http://www.calarts.edu/network

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Efficient matching

2007-05-21 Thread John W. Krahn
Karyn Williams wrote:

 I need to check for strings in a file. An example would be checking for a
 username in /etc/passwd or /var/log/maillog. The string is in another
 file, sometimes a single field on a line by itself, sometimes in a line
 with other strings. Based on what I have seen online and what I have done
 in other scripts I can :
 
 
 1. slurp the file into a single string and then check for a match.
 
 2. read the relevent field from the file into hash keys and check for a
 match.
 
 3. Loop through the file line by line and look for a match.
 
 
 Generally there are 1 - 2,000 strings, and 2,000 to 1,500,000 lines per
 file.
 
 I am wondering how these different methods may impact performance.

perldoc -q How do I efficiently match many regular expressions at once



John

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Parsing XML data

2007-05-21 Thread David Moreno Garza
Mike Blezien wrote:
 Hello,
 
 I am working with a XML gateway system which sends back response results in 
 XML format. I have been trying to work w/XML::Simple to parse the data, but 
 not too much success. This is a sample of the XML response data, the * 
 indicate the data we need to extract from XML file. I tried used 
 Data::Dumper to help, but didn't get the results I though, any help would 
 be much appreciated as the best way to parse this data.

I suggest you to use XML::TreePP.

-- 
David Moreno Garza [EMAIL PROTECTED] | http://www.damog.net/
 Pobre México: Tan lejos de Dios, tan cerca de los Estados Unidos.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Building hash record

2007-05-21 Thread Rodrick Brown

I have a few hundred records in a file like the following
a:1
a:2
a:3
b:1
b:2
b:3

I'm trying to build a hash of where the values on the left is the key and
for each value on the right is an array containing the coresponding values I
hope this makes sense

$a{$a} = [EMAIL PROTECTED]   where @values = {1,2,3}

I'm trying to do this on one pass if possible.

I'm have a bit of trouble contstructing this kind of data structure if
anyone can help me out it would be appreciated thanks. .


--
Rodrick R. Brown
http://www.rodrickbrown.com


Re: Parsing XML data

2007-05-21 Thread Mike Blezien
- Original Message - 
From: David Moreno Garza [EMAIL PROTECTED]

To: beginners@perl.org
Sent: Monday, May 21, 2007 8:23 PM
Subject: Re: Parsing XML data



Mike Blezien wrote:

Hello,

I am working with a XML gateway system which sends back response results in 
XML format. I have been trying to work w/XML::Simple to parse the data, but 
not too much success. This is a sample of the XML response data, the * 
indicate the data we need to extract from XML file. I tried used 
Data::Dumper to help, but didn't get the results I though, any help would 
be much appreciated as the best way to parse this data.


I suggest you to use XML::TreePP.



thanks, I think this'll do the trick. 


Mike

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Building hash record

2007-05-21 Thread Jeff Pang

Rodrick Brown 写道:

I have a few hundred records in a file like the following
a:1
a:2
a:3
b:1
b:2
b:3

I'm trying to build a hash of where the values on the left is the key and
for each value on the right is an array containing the coresponding 
values I

hope this makes sense

$a{$a} = [EMAIL PROTECTED]   where @values = {1,2,3}



Hello,

This one-line code could work fine for you.

perl -MData::Dumper -nle '($label,$id) = split/:/;push 
@{$HoA{$label}},$id;END {print Dumper \%HoA}' test.txt



--
http://home.arcor.de/jeffpang/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Building hash record

2007-05-21 Thread John W. Krahn
Rodrick Brown wrote:

 I have a few hundred records in a file like the following
 a:1
 a:2
 a:3
 b:1
 b:2
 b:3
 
 I'm trying to build a hash of where the values on the left is the key and
 for each value on the right is an array containing the coresponding values
 I hope this makes sense
 
 $a{$a} = [EMAIL PROTECTED]   where @values = {1,2,3}
 
 I'm trying to do this on one pass if possible.
 
 I'm have a bit of trouble contstructing this kind of data structure if
 anyone can help me out it would be appreciated thanks. .

my %a;
while ( FILE ) {
chomp;
my ( $key, $val ) = split /:/;
push @{ $a{ $key } }, $val;
}


John

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: Chinese word problem

2007-05-21 Thread Neil
Thank you very much, That's going to help 
My IM is ready for account [EMAIL PROTECTED] (sorry, my first time using
AIM). I'm using WEB AIM Express (I don't wanna install IM application in to
computer.) and added you into my buddy,

I tried the program in some other computer's (all intel x86) all got the
same result 3
, so I still got no clued.

Thank you.
Best Regard
Neil


-Original Message-
From: Jeff Pang [mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 17, 2007 10:22 AM
To: Perl Beginners
Subject: Re: Chinese word problem

Neil 写道:
 I did check the environment, 
 And set the same settings like your's,
 But the result still got 3
 
 Some thing different is that there are some warring from perl,
 And I have no clue how to deal with it.
 
 Thanks
 
 [EMAIL PROTECTED] perlPratice]# set | grep SHELL
 SHELL=/bin/bash

SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:
 monitor
 [EMAIL PROTECTED] perlPratice]# set | grep LC_ALL
 LC_ALL=C
 [EMAIL PROTECTED] perlPratice]# set | grep LANG
 LANG=en_US.en
 [EMAIL PROTECTED] perlPratice]# perl -le 'print length(我)'
 perl: warning: Setting locale failed.
 perl: warning: Please check that your locale settings:
 LANGUAGE = (unset),
 LC_ALL = (unset),
 LANG = en_US.en
 are supported and installed on your system.
 perl: warning: Falling back to the standard locale (C).
 3
 [EMAIL PROTECTED] perlPratice]#



Ok you can IM me if you'd like,let me see what happened actually on your
end.my aim: pangjr

-- 
http://home.arcor.de/jeffpang/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/