in reply to Parse csv file line by line

The code you posted doesn't produce the output you posted. However, it does seem to do what you want. So you haven't posted the portion of your code that is producing the problem. The following code was modified only in the formatting of its output, and where we're taking input from. Aside from that it's your code:

use strict; use warnings; my $sum = 0; while (my $line = <DATA>) { chomp $line; print "Original data:[$line]\n"; my ($target,$variables) = split (/;/ , $line); print "\t$target\n"; print "\t$variables\n"; } __DATA__ planet;World|Earth planet;celestial body|moon psychology;therapy|sociology psychology;humanity|sociology

...produces...

Original data:[planet;World|Earth] planet World|Earth Original data:[planet;celestial body|moon] planet celestial body|moon Original data:[psychology;therapy|sociology] psychology therapy|sociology Original data:[psychology;humanity|sociology] psychology humanity|sociology

Where's the problem?


Dave

Replies are listed 'Best First'.
Re^2: Parse csv file line by line
by albascura (Novice) on May 06, 2013 at 06:36 UTC

    This is exactly what I am not getting. I posted the whole code, but really, it works on the first line of the file and stops when it maches the ";" on the second line. I am really not getting why it is not working..

      Post the output of perl -V
        Summary of my perl5 (revision 5 version 12 subversion 3) configuration +: Platform: osname=darwin, osvers=11.0, archname=darwin-thread-multi-2level uname='darwin doublemagnum.apple.com 11.0 darwin kernel version 11 +.0.0: wed dec 22 11:00:23 pst 2010; root:xnu-1699.18.1~1release_x86_6 +4 x86_64 ' config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe -Dldflags= +-Dman3ext=3pm -Duseithreads -Duseshrplib -Dinc_version_list=none -Dcc +=llvm-gcc-4.2' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und +ef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='llvm-gcc-4.2', ccflags ='-arch x86_64 -arch i386 -g -pipe -fno +-common -DPERL_DARWIN -fno-strict-aliasing -fstack-protector -I/usr/l +ocal/include', optimize='-Os', cppflags='-g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing +-fstack-protector -I/usr/local/include' ccversion='', gccversion='4.2.1 (Based on Apple Inc. build 5658) ( +LLVM build 2335.15.00)', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +6 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='llvm-gcc-4.2 -mmacosx-version-min=10.7', ldflags ='-arch x86_6 +4 -arch i386 -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /usr/lib libs=-ldbm -ldl -lm -lutil -lc perllibs=-ldl -lm -lutil -lc libc=, so=dylib, useshrplib=true, libperl=libperl.dylib gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-arch x86_64 -arch i386 -bundle -undefi +ned dynamic_lookup -L/usr/local/lib -fstack-protector' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_64_ +BIT_ALL USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API Locally applied patches: /Library/Perl/Updates/<version> comes before system perl directori +es installprivlib and installarchlib points to the Updates directory Built under darwin Compiled at May 25 2011 17:53:29 @INC: /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.3/darwin-thread-multi-2level /Library/Perl/Updates/5.12.3 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .