Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

altering and printing an array

by s_gaurav1091 (Beadle)
on Dec 05, 2005 at 06:25 UTC ( [id://514050]=perlquestion: print w/replies, xml ) Need Help??

s_gaurav1091 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I am struck up at a problem. lets say ,I have got two arrays @versionArray = ("1.000.10.01","1.000.10.01"); @dateArray= ("110905,"111505"); Now I want my output form the arrays to be dispalyed like this
date version 11/09/05 1.000.10.01 11/15/05 1.000.10.01
Can anyone suggest what i should do?

Replies are listed 'Best First'.
Re: altering and printing an array
by Zaxo (Archbishop) on Dec 05, 2005 at 07:15 UTC

    BUU's reply is how I'd do it, but he forgot to rewrite the date in slashed format:

    print "date\tversion\n"; for (0..$#dateArray) { my $date = $dateArray[$_]; $date =~ s!^(\d\d)(\d\d)(\d\d)$!$1/$2/$3!; print "${date}\t$versionArray[$_]\n"; }
    I didn't alter the original array, just a copy of each element as it came up. There might be reason to get old-fashoned and look at perlform, or modern and Template Toolkit.

    After Compline,
    Zaxo

Re: altering and printing an array
by BUU (Prior) on Dec 05, 2005 at 06:34 UTC
    print "date\tversion\n"; for( 0..$#dateArray ) { print "$dateArray[$_]\t$versionArray[$_]\n"; }
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: altering and printing an array
by gopalr (Priest) on Dec 08, 2005 at 15:35 UTC

    Hi Gaurav,

    Use "pairwise" method of List::MoreUtils module.

    use List::MoreUtils qw(pairwise); @versionArray = ("1.000.10.01","1.000.10.01"); @dateArray= ("110905","111505"); @result=pairwise{replace($a, $b)} @dateArray, @versionArray; print "\ndate\t\tversion\n"; $"="\n"; print "\n@result"; sub replace { my ($a,$b)=@_; $a=~s#([0-9]{2})([0-9]{2})([0-9]{2})#$1/$2/$3#g; return "$a\t$b"; }

    Output:

    date version 11/09/05 1.000.10.01 11/15/05 1.000.10.01

    Thanks,
    Gopal.R

Re: altering and printing an array
by l.frankline (Hermit) on Dec 05, 2005 at 11:15 UTC

    Hi,

    Many of them suggested very well....I too have some suggestions. this can help u too.

    @dateArray = ("110905","111505"); @versionArray = ("1.000.10.01","1.000.10.01"); print "date\t-\tversion"; for ($i=0;$i<=$#dateArray;$i++) { print "\n$dateArray[$i]\t-\t$versionArray[$i]"; }

    Regards
    Franklin

    Don't put off till tomorrow, what you can do today.

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://514050]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2024-04-19 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found