Hi, On Fri, Dec 14, 2012 at 2:53 PM, samuel desseaux <sdesse...@gmail.com>wrote:
> Hi! > > I work in a library and i need to have several fields in one line > > Example > > I have this > > =995 \\$xPR$wLivre > =995 \\$bECAM$cECAM > =995 \\$n > =995 \\$oDisponible > =995 \\$kG1 42171 > > > and i want in one line > > =995 \\$bECAM$cECAM$kG1 42171$n$oDisponible$xPR$wLivre > Adding to Tim's wisdom Here is another way of doing it. use warnings; use strict; my %data_collection; while (<DATA>) { chomp; my ( $key, $value ) = split /\s+/, $_, 2; $data_collection{$key} .= $value; } print $data_collection{$_}, $/ for sort keys %data_collection; __DATA__ =995 \\$xPR$wLivre =995 \\$bECAM$cECAM =995 \\$n =995 \\$oDisponible =995 \\$kG1 42171 zz 1 zz 2 zz 3 rms 0xcafebabe rms 0xfed best, Shaji ------------------------------------------------------------------------------- Your talent is God's gift to you. What you do with it is your gift back to God. ------------------------------------------------------------------------------- ________________________________ From: timothy adigun <2teezp...@gmail.com> To: samuel desseaux <sdesse...@gmail.com> Cc: beginners@perl.org Sent: Saturday, 15 December 2012 10:43 AM Subject: Re: question of regexp or (another solution) Hi, On Fri, Dec 14, 2012 at 2:53 PM, samuel desseaux <sdesse...@gmail.com>wrote: > Hi! > > I work in a library and i need to have several fields in one line > > Example > > I have this > > =995 \\$xPR$wLivre > =995 \\$bECAM$cECAM > =995 \\$n > =995 \\$oDisponible > =995 \\$kG1 42171 > > > and i want in one line > > =995 \\$bECAM$cECAM$kG1 42171$n$oDisponible$xPR$wLivre > Using Dr., Ruud's data. This is another way of doing it: use warnings; use strict; my %data_collection; while (<DATA>) { chomp; my ( $key, $value ) = split /\s+/, $_, 2; push @{ $data_collection{$key} }, $value; } print $_, " ", @{ $data_collection{$_} }, $/ for keys %data_collection; __DATA__ =995 \\$xPR$wLivre =995 \\$bECAM$cECAM =995 \\$n =995 \\$oDisponible =995 \\$kG1 42171 zz 1 zz 2 zz 3 -- Tim