[bcn-pm] manipular un fitxer canviant xifres negatives per un zero

Stanislav web.perldev a gmail.com
dll mar 17 05:28:13 PDT 2014


Hello, Enric,

In this code int() just checks each row of the input file for an integer
value.
Glad to help you!

Best regards, Stanislav



2014-03-17 16:11 GMT+04:00 Agud Pique, Enric <eagud.q at tv3.cat>:

> Hello Stanislav,
>
> it runs properly! Thank you, what does it "int" in the code?
>
> Thank you
>
> Best
>
> Enric
> ________________________________
> De: Barcelona-pm [barcelona-pm-bounces+eagud.q=tv3.cat at pm.org] en nom de
> Stanislav [web.perldev at gmail.com]
> Enviat el: dilluns, 17 / març / 2014 10:17
> Per a: Barcelona Perl Mongers
> Tema: Re: [bcn-pm] manipular un fitxer canviant xifres negatives per un
> zero
>
> Hello!
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my ($file_in, $file_out) = ('in.txt', 'out.txt');
>
> open(my $in, '<', $file_in) or die "failed to open file $file_in: $!";
> open(my $out, '>', $file_out) or die "failed to open file $file_out: $!";
>
> while (<$in>) {
>     chomp;
>     $_ = 0 if int and $_ < 0;
>     print $out $_, "\n";
> }
>
> Does it help?
>
> Best regards, Stanislav
>
>
>
> 2014-03-17 12:44 GMT+04:00 Agud Pique, Enric <eagud.q at tv3.cat<mailto:
> eagud.q at tv3.cat>>:
> Hola gent,
>
> una consulta. Tinc un fitxer que amb dades. Totes les dades estan en una
> sola columna. Vull convertir tots els números negatius en zero i guardar el
> resultat, tota la columna de nou. Estic fent servir el següent codi però no
> sé si vaig bé. Suposo que he de llegir linea a linea...fent un
> chomp($linea) i si detecta un numero inferior a zero que el canvii a zero,
> pero quan arribo en aquest apartat no sé si el codi detecta que el que li
> passo es un numero o no....
>
> #!/usr/local/bin/perl
> use autodie;
>
> my $nombre = 'data.dat';
> my $nombre2 = 'data2.dat';
> open my $INFILE, '<', $nombre;
> my $linea;
> while ( $linea = <INFILE>) {
> chomp($linea);
> if ($linea< 0) {
> $linea==0    //aqui he de posar codi per convertir negatius a zero//
> }
> }
> open my $OUTFILE, '>', $nombre2;
> print   $OUTFILE "$linea";
> close   $OUTFILE;
>
> Gràcies
>
> Enric
> _______________________________________________
> llista dels Barcelona-pm
> Barcelona-pm at pm.org<mailto:Barcelona-pm at pm.org>
> http://mail.pm.org/mailman/listinfo/barcelona-pm
> BCN Perl Mongers: http://barcelona.pm.org
>
> _______________________________________________
> llista dels Barcelona-pm
> Barcelona-pm at pm.org
> http://mail.pm.org/mailman/listinfo/barcelona-pm
> BCN Perl Mongers: http://barcelona.pm.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/barcelona-pm/attachments/20140317/9b85066b/attachment.html>


Més informació sobre la llista de correu Barcelona-pm