[15794] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3207 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 30 14:06:25 2000

Date: Tue, 30 May 2000 11:05:23 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <959709922-v9-i3207@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 30 May 2000     Volume: 9 Number: 3207

Today's topics:
        a totally lame question: passwords on pages <eg344@nyu.edu>
    Re: array question <aahz@writeme.com>
        array questions <byteshif@cs.tu-berlin.de>
    Re: array questions (Kragen Sitaker)
    Re: array questions nobull@mail.com
    Re: BO's in Perl? (Kragen Sitaker)
    Re: can somebody help me in this program!! (Kragen Sitaker)
    Re: can somebody help me in this program!! (Kragen Sitaker)
        capturing password via Basic Auth <kkrieger@erols.com>
        CGI.pm function list/definitions <derek@ccil.org>
    Re: CGI.pm function list/definitions <red_orc@my-deja.com>
        command line argument (newbie) <frank@french-connexion.com>
    Re: command line argument (newbie) <tina@streetmail.com>
    Re: command line argument (newbie) <andkaha@my-deja.com>
    Re: command line argument (newbie) <billy@arnis-bsl.com>
    Re: command line argument (newbie) nobull@mail.com
        Data Hiding in OO Perl kdmasary@my-deja.com
    Re: Data Hiding in OO Perl <andkaha@my-deja.com>
    Re: Data Hiding in OO Perl excalibor@my-deja.com
    Re: directory permissions in NT scumjr@my-deja.com
    Re: Does this exist? <falkware@home.com>
        Embedded new lines in a comma delimited file joseph_stiehm@my-deja.com
        Embedded new lines in a comma delimited file joseph_stiehm@my-deja.com
    Re: Embedded new lines in a comma delimited file <billy@arnis-bsl.com>
    Re: Embedded new lines in a comma delimited file joseph_stiehm@my-deja.com
    Re: Embedded new lines in a comma delimited file (Kragen Sitaker)
        fileno DIRHANDLE <joepepin@att.com>
    Re: fileno DIRHANDLE <joepepin@att.com>
    Re: fileno DIRHANDLE <blah@nospam.com>
    Re: fileno DIRHANDLE <joepepin@att.com>
        Found one solution joseph_stiehm@my-deja.com
    Re: generating WML (Kragen Sitaker)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 30 May 2000 13:57:25 -0400
From: "Edward Grinvald" <eg344@nyu.edu>
Subject: a totally lame question: passwords on pages
Message-Id: <tjTY4.9$4N6.534@typhoon.nyu.edu>

Hi, please forgive my ignorance, but what is "the best" way to put password
protection on a page?

thanx

edward grinvald




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

Date: Tue, 30 May 2000 17:50:39 GMT
From: Andrew Collington <aahz@writeme.com>
Subject: Re: array question
Message-Id: <3933FE7A.5E0730A@writeme.com>

Thank you so much everyone who replied to my post!  I used the first
response as I only need to add one value at a time, and what was posted
worked great...

Thanks all!

Andy

Ilmari Karonen wrote:

> In article <8goj4i$v58$1@nnrp1.deja.com>, Ilja wrote:
> >In article <MPG.1398866f5a1832b698aaf0@nntp.hpl.hp.com>,
> >>     push @a, $new_value;
> >>     shift @a if @a > 5;
> >
> >Maybe if OP wanted to add many values:
> >
> >push @a, @new_values;
> >shift @a while @a > 5;
>
> Using splice is faster than multiple shifts:
>
>   push @a, @new_values;
>   splice @a, 0, @a - 5 if @a > 5;
>
> --
> Ilmari Karonen - http://www.sci.fi/~iltzu/
> Please ignore Godzilla and its pseudonyms - do not feed the troll.



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

Date: Tue, 30 May 2000 17:32:47 +0200
From: Michael Agbaglo <byteshif@cs.tu-berlin.de>
Subject: array questions
Message-Id: <3933DF1F.8982EBE6@cs.tu-berlin.de>

I'd like to initialize an array from a file

the file looks like:

col1:col2:col3:col4

the array looks like

@name[$col1,1]=3D$col2
@name[=A7col1,2]=3D$col3
@name[$col1,3]=3D$col4

is there an efficient way to do this ?

Is there an efficient way to search in a string whether something like
@name[,4] is contained ???

If you send a reply to this NG, please send me a copy - thanks.


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

Date: Tue, 30 May 2000 16:24:55 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: array questions
Message-Id: <rXRY4.126273$681.2378340@news-east.usenetserver.com>

In article <3933DF1F.8982EBE6@cs.tu-berlin.de>,
Michael Agbaglo  <byteshif@cs.tu-berlin.de> wrote:
>I'd like to initialize an array from a file
>
>the file looks like:
>
>col1:col2:col3:col4
>
>the array looks like
>
>@name[$col1,1]=$col2
>@name[§col1,2]=$col3
>@name[$col1,3]=$col4
>
>is there an efficient way to do this ?

I believe you have not written what you meant to write; I think you
mean something like

my ($key, @data) = split /:/;
$name{$key} = [@data];

Which puts col2 in $name{$key}->[0], col3 in $name{$key}->[1], col4 in
$name{$key}->[2].

>Is there an efficient way to search in a string whether something like
>@name[,4] is contained ???

I don't understand your question.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
The power didn't go out on 2000-01-01 either.  :)


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

Date: 30 May 2000 17:49:54 +0100
From: nobull@mail.com
To: Michael Agbaglo <byteshif@cs.tu-berlin.de>
Subject: Re: array questions
Message-Id: <u9hfbg56fh.fsf@wcl-l.bham.ac.uk>

Michael Agbaglo <byteshif@cs.tu-berlin.de> writes:

> I'd like to initialize an array from a file
> 
> the file looks like:
> 
> col1:col2:col3:col4
> 
> the array looks like
> 
> @name[$col1,1]=3D$col2
> @name[=A7col1,2]=3D$col3
> @name[$col1,3]=3D$col4

Looks like what!?!?!?!?!?

Did you perhaps mean:

$name[$col1][1]=$col2
$name[$col1][2]=$col3
$name[$col1][3]=$col4

> is there an efficient way to do this ?

while (<FILE>) {
  chomp;	
  my ($col1,@col2_4) = split /:/;
  $name[$col1] = [ undef, @col2_4 ]; 
}

BTW1: why don't you want to use $name[$col1][0] ?
BTW2: I do hope $col1 is always a small integer.

> Is there an efficient way to search in a string whether something like
> @name[,4] is contained ???

What do you mean by this?

Do you perhaps mean find the value of $col1 such that:
 $name[$col1][4] eq $string

Yes, sure create a hash.

my %name_indexed_by_col4 = map { $name[$_] => $_ if $name[$_] } 0 .. $#name;

Or do you perhaps mean find the value of $col1 such that:
 index($string,$name[$col1][4])

No, not really - you'll have to brute force it.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 30 May 2000 16:14:44 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: BO's in Perl?
Message-Id: <UNRY4.126180$681.2376331@news-east.usenetserver.com>

In article <8h0k2r$b5q$1@nnrp1.deja.com>,  <jdimov@my-deja.com> wrote:
>  Are Perl scripts absolutely safe from buffer overflows?  How exactly
>does Perl prevent BO's?

Unless there is a bug in the Perl interpreter, yes.  Perl keeps track
of the length and allocated length of every string; every place in the
interpreter where a string is being written into, Perl first ensures
that enough space is available, allocating more space for the string if
necessary.

Bugs in the Perl interpreter leading to buffer overflows have been
found in the past IIRC.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
The power didn't go out on 2000-01-01 either.  :)


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

Date: Tue, 30 May 2000 15:53:02 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: can somebody help me in this program!!
Message-Id: <ytRY4.125975$681.2370790@news-east.usenetserver.com>

In article <sj7givju5pj117@corp.supernews.com>,
Arun Mahajan  <arun67@yahoo.com> wrote:
>this is my first ever program and could not understand the problem why it 
>is not executing. see i am calling my cgi from the html code and want to 
>process it and it gives me internal server error. when i check it on 
>command line it gives me following description of errors:-
>
>errors:-
>-----------
>undefined value assgined to typeglob at cg-lib.pl line 58
>undefined value assgined to typeglob at cg-lib.pl line 58
>undefined value assgined to typeglob at cg-lib.pl line 58
>Use of unintiated value at ./accun-build.cgi at line 6
>Can't use an undefined value as filehandler reference at ./accn_build.cgi 6

These are not the errors you got; no Perl error messages contain the
words "assgined", "unintiated", or "filehandler".

>source code of my prog:-
>---------------------------
>#!/usr/bin/perl -w
>push(@INC, "/cgi-bin");
>require("cgi-lib.pl");
>
>&ReadParse(*input);
>open($PRICE_FILE, "data.tx");

*input is meaningless at this point, I believe, unless cgi-lib.pl gives
it some kind of meaning; also, $PRICE_FILE is undefined.  I think you
need to leave the $ off its beginning.

Actually, I think you need to forget about cgi-lib.pl and use CGI.pm
instead.

-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
The power didn't go out on 2000-01-01 either.  :)


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

Date: Tue, 30 May 2000 16:10:37 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: can somebody help me in this program!!
Message-Id: <1KRY4.126143$681.2375654@news-east.usenetserver.com>

In article <3933CAE8.F649B4A7@attglobal.net>,
Drew Simonis  <care227@attglobal.net> wrote:
>Arun Mahajan wrote:
>> errors:-
>> -----------
>> undefined value assgined to typeglob at cg-lib.pl line 58
>> undefined value assgined to typeglob at cg-lib.pl line 58
>> undefined value assgined to typeglob at cg-lib.pl line 58
>
>$modem = $input{'modem'}; #<-- line 58
>
>Undef value means that the script sees $input{'modem'} as the 
>undefined value, and is complaining about assigning that.

No.  Assigning undefined values does not produce warnings.  Ever.

Note also that this is not cgi-lib.pl.  Also note that the error
message as typed contains at least two misspellings; it wouldn't be
surprising if it were wrong in other ways as well.

>> Use of unintiated value at ./accun-build.cgi at line 6
>> Can't use an undefined value as filehandler reference at ./accn_build.cgi 6
>
>open($PRICE_FILE, "data.tx");  #<--- line 6
>
>Does data.tx exist?  You'll never know, since you aren't doing
>error checking on all your opens, like such:
>
>open($PRICE_FILE, "data.tx") or die "file not ready to open\n";  
>
>You can also check the return value of the open command for the 
>specific error.

Yes, but using $PRICE_FILE as a filehandle is never going to work
unless you put something in it first.  I think he means PRICE_FILE.

Of course you are correct that he should die if the open fails; he
should also insert $! into the error message so he can see why the file
couldn't be opened.

He's making an assumption about the current working directory, too,
which is often a bad idea with CGI scripts.

>One word of advice.  Learn and use CGI.pm.

Very good advice.  :)
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
The power didn't go out on 2000-01-01 either.  :)


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

Date: Tue, 30 May 2000 13:36:45 -0500
From: Kurt Krieger <kkrieger@erols.com>
Subject: capturing password via Basic Auth
Message-Id: <39340A3D.F5E18FFE@erols.com>

Hi,
I'm using Basic Authentication to provide access control to my web
pages, and that all works fine. However, I need to provide single
sign-on capability such that I can connect to additional servers as the
logged in user. To connect to the additional servers via perl, I need
both the username and the password of the logged in user.

Getting the username is trivial ($ENV{'REMOTE_USER'}, or CGI.pm's
user_name() sub), but I can't figure out how to get the password. I'm
very familiar with CGI.pm, but it doesn't provide a 'convenience'
function for password like it does user_name() for username. It also
doesn't seem to provide raw access to the received request header so
that I can manually parse it, pull out the base64 encoded
username:password string, then decode it.

I looked at HTTP::Headers, but was unable to get the info I needed, as
if its basic_authentication() sub could be used only to *set* the
values, not *get* them.

Any suggestions?

Platform: Solaris 2.7, iPlanet (Netscape) Webserver, iPlanet Directory
Server (LDAP), CGI.pm

Thanks a lot, Kurt



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

Date: Tue, 30 May 2000 17:15:35 GMT
From: Derek D'Angelo <derek@ccil.org>
Subject: CGI.pm function list/definitions
Message-Id: <8h0sv5$i9s$1@nnrp1.deja.com>

Where do I find the function list/definitions for CGI.pm?

Thanks

--
derek@ccil.org


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 17:41:57 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: CGI.pm function list/definitions
Message-Id: <8h0uh1$jf5$1@nnrp1.deja.com>

In article <8h0sv5$i9s$1@nnrp1.deja.com>,
  Derek D'Angelo <derek@ccil.org> wrote:
> Where do I find the function list/definitions for CGI.pm?
>
> Thanks
>
> --

You can find them on your perl system using:

perldoc CGI

or you can find them on:

http://www.cpan.org


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 17:21:50 +0200
From: frank <frank@french-connexion.com>
Subject: command line argument (newbie)
Message-Id: <3933DC8D.C66EAC22@french-connexion.com>

Hi all,

How can I pass variables thru the command line ?





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

Date: 30 May 2000 15:56:31 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: command line argument (newbie)
Message-Id: <8h0obe$268tc$6@fu-berlin.de>

hi,

frank <frank@french-connexion.com> wrote:

> How can I pass variables thru the command line ?

$ perlprogram.pl arg1 arg2

#!/usr/bin/perl -w

print $ARGV[0];
print $ARGV[1];
 ...

and you can even pass something through STDIN. see
perldoc perlrun
for more information.

tina


-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception


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

Date: Tue, 30 May 2000 16:01:12 GMT
From: Andreas Kahari <andkaha@my-deja.com>
Subject: Re: command line argument (newbie)
Message-Id: <8h0ojr$ekc$1@nnrp1.deja.com>

In article <3933DC8D.C66EAC22@french-connexion.com>,
  frank <frank@french-connexion.com> wrote:
> Hi all,
>
> How can I pass variables thru the command line ?
>
>

Try looking in @ARGV (see the perlvar manual).

/A

--
# Andreas Kähäri, <URL:http://hello.to/andkaha/>.
# All junk e-mail is reported to the
# appropriate authorities, no exceptions.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 16:10:59 GMT
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: command line argument (newbie)
Message-Id: <8h0p63$f3e$1@nnrp1.deja.com>

In article <3933DC8D.C66EAC22@french-connexion.com>,
  frank <frank@french-connexion.com> wrote:
> Hi all,
>
> How can I pass variables thru the command line ?
>
>

@ARGV

Consult your local perldoc perlvar or
http://www.cpan.org/doc/manual/html/pod/perlvar.html.

Ilja.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 30 May 2000 17:50:59 +0100
From: nobull@mail.com
Subject: Re: command line argument (newbie)
Message-Id: <u9em6k56do.fsf@wcl-l.bham.ac.uk>

frank <frank@french-connexion.com> writes:

> How can I pass variables thru the command line ?

To all intents and purposes you can't (you'll have to make your script
parse the command line) but see also the answers given to this question
last time it was asked here.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 30 May 2000 16:47:07 GMT
From: kdmasary@my-deja.com
Subject: Data Hiding in OO Perl
Message-Id: <8h0ra5$gso$1@nnrp1.deja.com>

I have started a new project in Perl and I wish to keep things as
Object Oriented as possible. I've discovered, so far, that Perl's
equivalent of the C++ 'class' is the 'package.' I've played around with
the syntax a bit and now have (almost) no problems creating my objects.

The only problem I do have is with Data Hiding. It appears to me that
this fundamental concept of OOP is not supported in Perl. Could this be
true? Or have I overlooked something?

Here's a little example:

=========================
package Foo;

sub new
{
    my $pkg = shift;
    my $data = "Hidden Data!";

    bless { data => $data }, $pkg;
}

package main;

my $obj = new Foo;

print "No secrets: ", $obj->{data}, "\n";
=======================

I expected the print line to error out at $obj->{data} but, alas, the
data is printed. Is there no way to make Foo's $data private?

Thanks,
Kevin Masaryk


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 16:55:21 GMT
From: Andreas Kahari <andkaha@my-deja.com>
Subject: Re: Data Hiding in OO Perl
Message-Id: <8h0rpg$hb2$1@nnrp1.deja.com>

In article <8h0ra5$gso$1@nnrp1.deja.com>,
  kdmasary@my-deja.com wrote:
> I have started a new project in Perl and I wish to keep things as
> Object Oriented as possible. I've discovered, so far, that Perl's
> equivalent of the C++ 'class' is the 'package.' I've played around
with
> the syntax a bit and now have (almost) no problems creating my
objects.
>
> The only problem I do have is with Data Hiding. It appears to me that
> this fundamental concept of OOP is not supported in Perl. Could this
be
> true? Or have I overlooked something?
>

I don't feel that data hiding is a fundamental concept of OO. The more
fundamental concept I'm thinking of is "encapsulation", which Perl does
splendidly with its packages. But yes, you can do data hiding in Perl
too.

Damina Conway wrote a nice book describing how to implement OO in Perl
(see <URL:http://www.manning.com/Conway/>).

Chapter 11 (and 3) of the book (which happens to be about encapsulation)
is available on the web as a PDF file (see the URL above).

Buy the book. It's good. (and you get to read about how to bless a
subroutine, typebglob or a regular expression into an object!)

/A

--
# Andreas Kähäri, <URL:http://hello.to/andkaha/>.
# All junk e-mail is reported to the
# appropriate authorities, no exceptions.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 17:39:34 GMT
From: excalibor@my-deja.com
Subject: Re: Data Hiding in OO Perl
Message-Id: <8h0ucj$jc7$1@nnrp1.deja.com>

Hi,

In article <8h0rpg$hb2$1@nnrp1.deja.com>,
  Andreas Kahari <andkaha@my-deja.com> wrote:
> In article <8h0ra5$gso$1@nnrp1.deja.com>,
>   kdmasary@my-deja.com wrote:
> > I have started a new project in Perl and I wish to keep things as
> > Object Oriented as possible. <snip> The only problem I do have is
with Data Hiding.

> I don't feel that data hiding is a fundamental concept of OO. The more
> fundamental concept I'm thinking of is "encapsulation", which Perl
does
> splendidly with its packages. But yes, you can do data hiding in Perl
> too.
>
> Damina Conway wrote a nice book describing how to implement OO in Perl
> (see <URL:http://www.manning.com/Conway/>).
>
> Chapter 11 (and 3) of the book (which happens to be about
encapsulation)
> is available on the web as a PDF file (see the URL above).
>
> Buy the book. It's good. (and you get to read about how to bless a
> subroutine, typebglob or a regular expression into an object!)
>
> /A

not exactly a "me too!" post, but almost... I won't try to explain what
Damian does much, much better than I do...

Just a hint for you to discover it by yourself (one o fthe techniques,
at least):

look up 'closures' in the Perl documentation and you have found a really
powerful way to make paranoid classes that won't let you snoop into the
data... (closures should be in perlref or around there...)

By all means read Damian's chapters about the subject on-line (thanks
for putting them available on-line!)... And get the book, I'm getting it
as soon as the dollar stops making my checkbook tremble... (h&s is
almost higher than the book itself!)

welcome to Perl OO :)
d@


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 17:51:15 GMT
From: scumjr@my-deja.com
Subject: Re: directory permissions in NT
Message-Id: <8h0v2b$jui$1@nnrp1.deja.com>

Well....I still couldn't get the file tests to work, but I did find
another way around the problem (I'm not sure why I didn't think of it
before).   I've been using chdir() to change to the desired
directory....and it returns a success or failure!

Thanks again,

SJ


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 16:16:20 GMT
From: Falk <falkware@home.com>
Subject: Re: Does this exist?
Message-Id: <p9q7js8ningpinljgp67k1kfoklj4g80ip@4ax.com>

Reply to: NagaPutih <s0218327@unix1.cc.ysu.edu>
Subject: Re: Does this exist?
Date: Mon, 29 May 2000 02:34:55 -0400
Newsgroup(s): comp.lang.perl.misc

Quote:
>if it was your first post, you'll get e-mail which you have to reply
>to approve yourself to post.
>if it isn't, and i assume you haven't approved yourself, start your
>posting by putting "passme" on the first line by itself.
>however, you may want to check the following url before posting:
>http://www.boutell.com/openfaq/cgi
>hope this helps.

Thank you so much for your help... I appreciate it...



--
#!/user/Falk
#!/Falkware dot com: http://www.falkware.com
#!/FDC BBS: http://www.falkware.com/fdcbbs/
#!/Visit http://www.shoppersanonymous.net


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

Date: Tue, 30 May 2000 15:25:46 GMT
From: joseph_stiehm@my-deja.com
Subject: Embedded new lines in a comma delimited file
Message-Id: <8h0mhr$h3q$1@nnrp2.deja.com>

Here's a regexp question that's giving me fits:

I've got a comma-delimited text file with embedded (carriage return+new
line)'s -

ex.
1,2,"abcdef
ghij",3,4,"hello"

Anybody know of a regular expression to strip the embedded carriage
return+new line?

Thanks.

Joseph Stiehm
jstiehm@cisco.com


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 15:25:47 GMT
From: joseph_stiehm@my-deja.com
Subject: Embedded new lines in a comma delimited file
Message-Id: <8h0mhs$h3r$1@nnrp2.deja.com>

Here's a regexp question that's giving me fits:

I've got a comma-delimited text file with embedded (carriage return+new
line)'s -

ex.
1,2,"abcdef
ghij",3,4,"hello"

Anybody know of a regular expression to strip the embedded carriage
return+new line?

Thanks.

Joseph Stiehm
jstiehm@cisco.com


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 15:42:55 GMT
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: Embedded new lines in a comma delimited file
Message-Id: <8h0nhr$dsn$1@nnrp1.deja.com>

In article <8h0mhs$h3r$1@nnrp2.deja.com>,
  joseph_stiehm@my-deja.com wrote:
> Here's a regexp question that's giving me fits:
>
> I've got a comma-delimited text file with embedded (carriage return+new
> line)'s -
>
> ex.
> 1,2,"abcdef
> ghij",3,4,"hello"
>
> Anybody know of a regular expression to strip the embedded carriage
> return+new line?
>

IMHO:

To strip _all_ CR's and LF's:

$string =~ tr/\r\n//d;

To strip only CR/LF _pairs_:

$string =~ s/\r\n//g;

Maybe for platforms where CR/LF codes are different from ones in
your data file replace \r with \012 and \n with \015.

Hope this helps.
Ilja.



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 16:05:15 GMT
From: joseph_stiehm@my-deja.com
Subject: Re: Embedded new lines in a comma delimited file
Message-Id: <8h0orc$eth$1@nnrp1.deja.com>

Ilja,

Thanks. Unfortunately, perhaps I was not specific enough about my
problem.  I'm trying to eliminate the cr/nl that are embedded within a
field (double-quoted field).  I want the cr/nl's that are actually end
of lines to remain.

- Joseph
jstiehm@cisco.com

In article <8h0nhr$dsn$1@nnrp1.deja.com>,
  Ilja Tabachnik <billy@arnis-bsl.com> wrote:
> In article <8h0mhs$h3r$1@nnrp2.deja.com>,
>   joseph_stiehm@my-deja.com wrote:
> > Here's a regexp question that's giving me fits:
> >
> > I've got a comma-delimited text file with embedded (carriage
return+new
> > line)'s -
> >
> > ex.
> > 1,2,"abcdef
> > ghij",3,4,"hello"
> >
> > Anybody know of a regular expression to strip the embedded carriage
> > return+new line?
> >
>
> IMHO:
>
> To strip _all_ CR's and LF's:
>
> $string =~ tr/\r\n//d;
>
> To strip only CR/LF _pairs_:
>
> $string =~ s/\r\n//g;
>
> Maybe for platforms where CR/LF codes are different from ones in
> your data file replace \r with \012 and \n with \015.
>
> Hope this helps.
> Ilja.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 16:33:30 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Embedded new lines in a comma delimited file
Message-Id: <u3SY4.126348$681.2379989@news-east.usenetserver.com>

In article <8h0mhs$h3r$1@nnrp2.deja.com>,  <joseph_stiehm@my-deja.com> wrote:
>Here's a regexp question that's giving me fits:
>
>I've got a comma-delimited text file with embedded (carriage return+new
>line)'s -
>
>ex.
>1,2,"abcdef
>ghij",3,4,"hello"
>
>Anybody know of a regular expression to strip the embedded carriage
>return+new line?

I have done this before; it is not a trivial thing.  I think there are
CSV Perl modules to handle it.  Look on CPAN.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
The power didn't go out on 2000-01-01 either.  :)


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

Date: Tue, 30 May 2000 11:15:35 -0400
From: "Joe Pepin" <joepepin@att.com>
Subject: fileno DIRHANDLE
Message-Id: <8h0llh$f6h6@kcweb01.netnews.att.com>

Not surprisingly, fileno DIRHANDLE doesn't work.  Is there any other way to
get the file descriptor of a DIRHANDLE?






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

Date: Tue, 30 May 2000 11:32:03 -0400
From: "Joe Pepin" <joepepin@att.com>
Subject: Re: fileno DIRHANDLE
Message-Id: <8h0mkf$f6h7@kcweb01.netnews.att.com>

Also, local *DIRHANDLE doesn't seem to close when the DIRHANDLE goes out of
scope, unlinke a *FILEHANDLE.

"Joe Pepin" <joepepin@att.com> wrote in message
news:8h0llh$f6h6@kcweb01.netnews.att.com...
> Not surprisingly, fileno DIRHANDLE doesn't work.  Is there any other way
to
> get the file descriptor of a DIRHANDLE?
>
>
>
>




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

Date: Tue, 30 May 2000 18:23:36 +0200
From: Marco Natoni <blah@nospam.com>
Subject: Re: fileno DIRHANDLE
Message-Id: <3933EB08.2B9ED744@nospam.com>

Joe,

Joe Pepin wrote:
> Not surprisingly, fileno DIRHANDLE doesn't work.  Is there any 
> other way to get the file descriptor of a DIRHANDLE?

  A directory is just a file with a valid handle only on some systems. 
I suppose that Windows is not one of those systems.


	Best regards,
		Marco


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

Date: Tue, 30 May 2000 13:05:44 -0400
From: "Joe Pepin" <joepepin@att.com>
Subject: Re: fileno DIRHANDLE
Message-Id: <8h0s4a$f6h8@kcweb01.netnews.att.com>

Maybe, but this was on a Solaris.  Think I've caught a bug, or at least
something that should be documented.

"Marco Natoni" <blah@nospam.com> wrote in message
news:3933EB08.2B9ED744@nospam.com...
> Joe,
>
> Joe Pepin wrote:
> > Not surprisingly, fileno DIRHANDLE doesn't work.  Is there any
> > other way to get the file descriptor of a DIRHANDLE?
>
>   A directory is just a file with a valid handle only on some systems.
> I suppose that Windows is not one of those systems.
>
>
> Best regards,
> Marco




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

Date: Tue, 30 May 2000 16:33:49 GMT
From: joseph_stiehm@my-deja.com
Subject: Found one solution
Message-Id: <8h0qhd$ga5$1@nnrp1.deja.com>

Here's the solution I used, albeit without regexp.  Anybody know a more
elegant solution?

- Joseph

#!/usr/local/bin/perl

$FILEIN = $ARGV[0];
open FILEIN or die "can't open $FILEIN: $!\n";
open(FILEOUT,">FileOut.csv") or die "Cannot create FileOut.csv: $!\n";
$quotes = 0;
while (<FILEIN>) {
    $line = $_;
    while ($line =~ m/"/g) {
      $quotes++;
      }
    if (int($quotes/2) != ($quotes/2)) {
      chomp($line);
      }
    print FILEOUT $line;
}
close FILEOUT or die "Cannot close FileOut.csv: $!\n";
close FILEIN or die "Cannot close $FILEIN: $!\n";


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 30 May 2000 16:12:11 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: generating WML
Message-Id: <vLRY4.126158$681.2375990@news-east.usenetserver.com>

In article <3933cd23$1@einstein.hhs.nl>, Wouter <wouter@quicknet.nl> wrote:
>I am a beginning perl-programmer, so excuse me for making terrible mistakes.
>
>I would like to generate WML just like it is possible to generate html. Is
>this already possible and if so. Could anyone give me a clue?

Yes, this is possible.  But it is not related to Perl.  Good luck
finding a relevant newsfroup.


-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
The power didn't go out on 2000-01-01 either.  :)


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3207
**************************************


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