CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [hwnd] How to join hash keys with data output?: Edit Log



Zhris
Enthusiast

Jun 1, 2013, 1:07 PM


Views: 548
Re: [hwnd] How to join hash keys with data output?

Hi,

My attempt is highly dependent on input data order and format:


Code
#!/usr/bin/perl 
use strict;
use warnings;
use Data::Dumper;

my ( $data, $title, $id );

while ( my ( $key, $value ) = split /\:\s/, <DATA> )
{
$value =~ s/\s?\r?\n$//;

$key eq q/title/ ? $title = $value :
$key eq q/id/ ? $id = $value :
$key eq q/num/ ? $data->{qq/$title-$id/} = $value :
undef ;
}

print Dumper( $data );

__DATA__
title: foo
id: 1
num: 1 2 3 4 5
id: 2
num: 6 7 8 9 10
title: bar
id: 1
num: 1 2 3 4 5
id: 2
num: 6 7 8 9 10


Chris


(This post was edited by Zhris on Jun 1, 2013, 1:27 PM)


Edit Log:
Post edited by Zhris (Enthusiast) on Jun 1, 2013, 1:11 PM
Post edited by Zhris (Enthusiast) on Jun 1, 2013, 1:15 PM
Post edited by Zhris (Enthusiast) on Jun 1, 2013, 1:27 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives