[25991] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8210 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 28 14:05:19 2005

Date: Tue, 28 Jun 2005 11:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 28 Jun 2005     Volume: 10 Number: 8210

Today's topics:
        CSV_XS: removing leading '0' from a parsed field <lard@tardis.ed.ac.molar.uk>
    Re: CSV_XS: removing leading '0' from a parsed field <lard@tardis.ed.ac.molar.uk>
    Re: FAQ 4.42 How can I tell whether a certain element i <sbertho@alussinan.org>
        How  to read ipi_ifindex/ip_pktinfo/in_pktinfo packet d <junkto@tm.net.my>
    Re: perl script <sherm@dot-app.org>
    Re: Simple Structure Question <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 28 Jun 2005 12:30:41 GMT
From: Alex Hunsley <lard@tardis.ed.ac.molar.uk>
Subject: CSV_XS: removing leading '0' from a parsed field
Message-Id: <Rpbwe.8649$G2.7678@fe1.news.blueyonder.co.uk>

I'm using CSV_XS to parse a CSV file.
One of my CSV fields beings with the 0 char as it is a phone number, e.g.:

"0123456789"

However, the string returned from CSV_XS when I parse the line doesn't 
have the leading 0. I think this may be because it is intrepretting it 
as a number at some point, and hence dropping the leading 0?
Anyway, my code for reading my file is as follows:

use DBI;

use DBD::mysql;

use Text::CSV_XS;
use File::Find;

#$vah = "07";
#print $vah;
#exit;

$csv = Text::CSV_XS->new(
	{
		'quote_char'   => '"',
		'escape_char'  => '"',
		'sep_char'     => ',',
		'binary'       => 0,
		'always_quote' => 1
	}
);

open(INPUT,"<sheet.csv") || die "couldn't open input";


while (<INPUT>) {
    $inputLine = $_;

#skip blank lines
	if ( $inputLine =~ /^\s*$/ ) {
		next;
	}


# parse a CSV string into fields
    $readStatus = $csv->parse($inputLine);
    @columns = $csv->fields();    # get the parsed fields

    # this folllowing line output lines like 1234
    # rather than the expected 01234!

    print "$columns[9]\n";


  }

close(INPUT);


grateful for any guidance here...
thanks
alex


------------------------------

Date: Tue, 28 Jun 2005 12:54:56 GMT
From: Alex Hunsley <lard@tardis.ed.ac.molar.uk>
Subject: Re: CSV_XS: removing leading '0' from a parsed field
Message-Id: <AMbwe.8771$G2.6123@fe1.news.blueyonder.co.uk>

Alex Hunsley wrote:
> I'm using CSV_XS to parse a CSV file.
> One of my CSV fields beings with the 0 char as it is a phone number, e.g.:
> 
> "0123456789"
> 
> However, the string returned from CSV_XS when I parse the line doesn't 
> have the leading 0. I think this may be because it is intrepretting it 
> as a number at some point, and hence dropping the leading 0?
> Anyway, my code for reading my file is as follows:
> 
> use DBI;

d'oh! Please ignore last post.
Turns out I managed to remove the 0 myself by saving the spreadsheet 
without the column set to the right type. Nothing to do with CSV_XS or perl.

alex


------------------------------

Date: Tue, 28 Jun 2005 13:37:01 +0000 (UTC)
From: SB <sbertho@alussinan.org>
Subject: Re: FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
Message-Id: <d9rjp6$18sa$1@vishnu.jussieu.fr>

PerlFAQ Server <com...@panix.com> :

> If the values are all small integers, you could use a simple indexed
> array. This kind of an array will take up less space:
> [...]
> If the values in question are integers instead of strings, you can save
> quite a lot of space by using bit strings instead:
> [...]
> If you're only testing once, then use:
> [...]

Is there a standard implementation of &is_in_array, implementing one of the above
methods, in CPAN or somewhere else?


------------------------------

Date: Tue, 28 Jun 2005 23:48:24 +0800
From: Lincoln Yeoh <junkto@tm.net.my>
Subject: How  to read ipi_ifindex/ip_pktinfo/in_pktinfo packet data?
Message-Id: <fkr2c1189qo4uqk6c6fks1pltaofs4f3cg@4ax.com>

Hi,

On Linux, it seems to check which network interface a packet (e.g.
udp) is coming from one is supposed to set the necessary socket
options and then read the ip_pktinfo/in_pktinfo message and then
determine the ipi_ifindex value. A similar thing is supposed to be
done to choose which interface to send a packet out from.

But how does one do that in perl?

Why? I'm wondering whether it's possible to write a DHCP server in
perl, and one which works with multiple network interfaces. So far I
haven't seen one yet.

Cheerio!

Link.


------------------------------

Date: Tue, 28 Jun 2005 07:10:36 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: perl script
Message-Id: <87k6keu47n.fsf@dot-app.org>

Tim Hammerquist <tim@vegeta.ath.cx> writes:

> You probably meant:
>
>    open(INFILE, $ARGV[0]) or die "can't open $ARGV[0]";

Even better, explain *why* the file can't be opened:

    open(INFILE, $ARGV[0]) or die "Can't open $ARGV[0]: $!";

sherm--

-- 
Due to the amount of unreadable gibberish being posted from Google Groups,
I seldom read messages posted from there.

Cocoa/Perl: http://camelbones.sf.net       Hire Me: http://www.dot-app.org


------------------------------

Date: Tue, 28 Jun 2005 07:57:00 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Simple Structure Question
Message-Id: <slrndc2i8s.65a.tadmc@magna.augustmail.com>

Joe Smith <joe@inwap.com> wrote:
> one man army wrote:
>>  Can someone explain this line?


>>       $url = $token->[1]{href} || "-";

> If the value
> corresponding to the keys is undefined or zero or "0", 


Or the empty string. (you missed one of the four false values)


> then the
> value of "-" will be used.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8210
***************************************


home help back first fref pref prev next nref lref last post