develooper Front page | perl.beginners | Postings from July 2003

Re: Pipe Delimited File

Thread Previous | Thread Next
From:
Rob Dixon
Date:
July 29, 2003 16:28
Subject:
Re: Pipe Delimited File
Message ID:
20030729232801.12586.qmail@onion.perl.org
Pablo Fischer wrote:
> Checking My code and trying with this:
>
> open(ARCHIVO, "MOVER.CPO");
> my $file = <ARCHIVO>; #Yes I know that I need to use and array, just trying
> #Cerramos el archivo
> close(ARCHIVO);
> #open ARCHIVO, 'MOVER.CPO' or die "Cannot open MOVER.CPO: $!";
> my ($num, $fulanos, $tiempo, $subject, @bodyhtml, @bodytxt, $attach,
> $fechaenvio ) = split (/\|/, $file);
>
> print "The Number: $num\n";
> print "Fulanos: $fulanos\n";
> print "Time: $tiempo\n";
> print "Subject: $subject\n";
> print "BodyHTML: $bodyhtml\n";
> print "BodyTXT: $bodytxt\n";
> print "Attachment: $attach\n";
> print "Date: $fechaenvio\n";
>
> Now What I get:
>
> The Number: 3
> Fulanos: Archivo1, Archivo2, ARchivo3
> Time: 13
> Subject: COMOESTAS
> BodyHTML:
> BodyTXT:
> Attachment:
> Date:
>
>
> And its working, ONLY with the first line :-(, I know why, cause Im not using
> an array to load the FILE :-(
>
> MOVER.CPO
> 3|Archivo1, Archivo2, ARchivo3|13|COMOESTAS|
> <body>
> Special Promotions
> </body>
> >
> Special Promotions
> > /home/unmada/Programacion/Perl|20030408

Hi Pablo.

Is there only one record in the file? Or is there something to separate the
'Date' field of the first record from the 'Number' field of the next one?

If there is only a single record in the file then you need to read the
whole file into a single scalar like this.

  open ARCHIVO, 'MOVER.CPO' or die "Cannot open MOVER.CPO: $!";
  local $/;
  my $file = <ARCHIVO>;
  close ARCHIVO;

  my (
    $num,
    $fulanos,
    $tiempo,
    $subject,
    $bodyhtml,
    $bodytxt,
    $attach,
    $fechaenvio ) = split (/\|/, $file);

  print "The Number: $num\n";
  print "Fulanos: $fulanos\n";
  print "Time: $tiempo\n";
  print "Subject: $subject\n";
  print "BodyHTML: $bodyhtml\n";
  print "BodyTXT: $bodytxt\n";
  print "Attachment: $attach\n";
  print "Date: $fechaenvio\n";

But if there's more than one then you need to explain to us
how they're separated.

I hope this helps,

Rob



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About