Hi John!
--- "John W. Krahn" <[EMAIL PROTECTED]> wrote:
> Here is one way to do it:
>
> my @array = qw( favorite lessfavorite worstfavorite
> );
>
> while ( <DATA> ) {
> chomp;
> my @fields = map length() ? $_ : 'NA', split
> /:/, $_, -1;
>
> next unless @fields == @array;
>
> my %pairs;
> @pairs{ @array } = @fields;
>
> print map( "$_: $pairs{$_} ", @array ), "\n";
> }
>
>
> __DATA__
> dog:cat:bird
> ::
> one::three
> four:five:
I'm just so glad it worked perfect! But I'm just
amazed about it that I really want to know how did you
figured it out.
So far here's the working code:
#!/usr/local/bin/perl
use warnings;
use strict;
my $input = shift @ARGV;
my $output = shift @ARGV;
my @attributes = qw(ipNetworkNumber Prefix
ipNetmaskNumber Range BID PID ipAssignedTo
description RID Region Area SID
ipAllocStatus manager ipAssignedDate
TID ipNetworkType 2ndOF inetNum );
open INPUT, "$input" or die $!;
open OUTPUT, ">$output" or die $!;
while (<INPUT>){
chomp;
#s/:$/:NA/g;
#s/:(?=:)/:NA/g;
#This line is too tricky for me, all I know is that it
has a ternary hook operator which returns $_ if the
expression my @fields = map length() is true,
otherwise, substitute empty fields with 'NA'. I looked
into perldoc -f map as well as length() and as far as
I can only understand, an empty argument pass to
length will make use of $_. While the 'map' as used in
example on perldoc would translate a list of numbers
to their corresponding character using this line:
@chars = map(chr, @nums);
Would you mind explaining me how did you tell it to
substitute empty cells with 'NA' using the line below?
I just can't seem to find any sort of like this
substitution using, 's/ /NA/g'
my @fields = map length() ? $_ : 'NA', split /:/, $_,
-1;
next unless @fields == @attributes;
my %pairs;
@pairs{ @attributes } = @fields;
print OUTPUT map( "$_: $pairs{$_}\n", @attributes ),
"\n";
Thank you very much for your time. I will just try to
figure out the rest of your codes myself.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>