[16453] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3865 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 31 21:10:27 2000

Date: Mon, 31 Jul 2000 18:10:17 -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: <965092217-v9-i3865@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 31 Jul 2000     Volume: 9 Number: 3865

Today's topics:
    Re: splitting on spaces <dietmar.staab@t-online.de>
    Re: splitting on spaces <tina@streetmail.com>
    Re: splitting on spaces <tina@streetmail.com>
    Re: splitting on spaces <dietmar.staab@t-online.de>
    Re: splitting on spaces <lr@hpl.hp.com>
    Re: Syntax Question bardicstorm@my-deja.com
    Re: Syntax Question <tina@streetmail.com>
    Re: Syntax Question <lr@hpl.hp.com>
    Re: Syntax Question <peter.sundstrom@eds.com>
    Re: text file to html <flavell@mail.cern.ch>
    Re: Uploading images via Perl script <red_orc@my-deja.com>
    Re: Use MIME *and* specify the mail server <care227@attglobal.net>
        Variable Interpolation Woes abliss@mindspring.com
    Re: Variable Interpolation Woes <tina@streetmail.com>
    Re: Variable Interpolation Woes (Clinton A. Pierce)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 01 Aug 2000 00:36:20 -0500
From: "Dietmar Staab" <dietmar.staab@t-online.de>
Subject: Re: splitting on spaces
Message-Id: <8m4uvr$ir9$14$1@news.t-online.com>

In article <8m4s8e$5mcr3$8@ID-24002.news.cis.dfn.de>, Tina Mueller
<tina@streetmail.com> wrote:
Hallo Tina,
> it does? I get 16 elements in @myarray (that's not wat the poster wants,
> I guess). perhaps you meant

(you can find this in English in your the documentation) ;-)

die 16 Elemente erhälst Du aber nur, wenn Du einige Leerzeichen mehr
einfügst.  Wird jedes Wort nur durch ein Leerzeichen getrennt, dann sind
beide Lösungen identisch. Wenn als expression split(/\s+/, $string)
angegeben wird, dann sind beide identisch. Das / /-split ergibt noch
Null-Werte (bei den überschüssigen Leerzeichen), während das mit den
Anführungszeichen sich wie awk verhält. Gibt es dafür irgendeinen Grund,
daß man einmal das Verhalten von awk simuliert und einmal nicht. Das mit /
/-Mustern würde doch vollkommen ausreichen - oder steht da wieder der
Satz, daß man das so machen kann, wie es einem beliebt? 

Gruesse, Dietmar


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

Date: 31 Jul 2000 22:49:29 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: splitting on spaces
Message-Id: <8m4vpp$5mcr3$10@ID-24002.news.cis.dfn.de>

hi,

please stay with english, at least when posting here.
you should've mailed me. (in case you want to posdt
in german again, fup2p is set)

Dietmar Staab <dietmar.staab@t-online.de> wrote:
> In article <8m4s8e$5mcr3$8@ID-24002.news.cis.dfn.de>, Tina Mueller
> <tina@streetmail.com> wrote:
> Hallo Tina,
>> it does? I get 16 elements in @myarray (that's not wat the poster wants=
,
>> I guess). perhaps you meant

> (you can find this in English in your the documentation) ;-)

> die 16 Elemente erh=E4lst Du aber nur, wenn Du einige Leerzeichen mehr
> einf=FCgst.

i get 16 elements with the test string
my $string =3D "Hello how can    I       help  you";
my @array =3D split / /,$string;

but i get 6 elements (just the words, as the poster
wanted (!)) with:
my $string =3D "Hello how can    I       help  you";
my @array =3D split ' ',$string; # which is the same as
                               # my @array =3D split /\s+/,$string

>  Wird jedes Wort nur durch ein Leerzeichen getrennt, dann sind
> beide L=F6sungen identisch. Wenn als expression split(/\s+/, $string)
> angegeben wird, dann sind beide identisch. Das / /-split ergibt noch
> Null-Werte (bei den =FCbersch=FCssigen Leerzeichen), w=E4hrend das mit d=
en
> Anf=FChrungszeichen sich wie awk verh=E4lt. Gibt es daf=FCr irgendeinen =
Grund,
> da=DF man einmal das Verhalten von awk simuliert

yes, right, split ' ',$string behaves like awk, as the documentation
of split says. but that is what the poster wanted.
please look at the original post.

> und einmal nicht. Das mit /
> /-Mustern w=FCrde doch vollkommen ausreichen - oder steht da wieder der
> Satz, da=DF man das so machen kann, wie es einem beliebt?=20

you mean, TIMTOWTDI?
well, here split ' ',$string is not only better
than split / /,$string because the latter one
does not solve the problem.

(of course, you can say spli /\s+/,$string
if you want.)

tina

--=20
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please no answers via email unless followup is set to poster.


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

Date: 31 Jul 2000 23:06:09 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: splitting on spaces
Message-Id: <8m50p1$5mcr3$12@ID-24002.news.cis.dfn.de>

Tina Mueller <tina@streetmail.com> wrote:

> my @array = split ' ',$string; # which is the same as
>                                # my @array = split /\s+/,$string

sorry, of course not exactly the same. for details lookup
perldoc -f split

tina


-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please no answers via email unless followup is set to poster.


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

Date: Tue, 01 Aug 2000 01:34:23 -0500
From: "Dietmar Staab" <dietmar.staab@t-online.de>
Subject: Re: splitting on spaces
Message-Id: <8m52cn$go5$10$1@news.t-online.com>

In article <8m4vpp$5mcr3$10@ID-24002.news.cis.dfn.de>, Tina Mueller
<tina@streetmail.com> wrote:

> hi,
> 
> please stay with english, at least when posting here. you should've
> mailed me. (in case you want to posdt in german again, fup2p is set)

uups, I've choosen the wrong entry in the menubar of my newsreader - when
sending is confirmed it's hard to delete postings from a newsgroup. :-(


But since there's nothing new about the question in my former posting there's
no need to translate it. 

>> my @array = split ' ',$string; # which is the same as
>>                                # my @array = split /\s+/,$string
> 
> sorry, of course not exactly the same. 

I know, leading spaces will create a null entry. ;-)

Greetings, Dietmar


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

Date: Mon, 31 Jul 2000 16:37:55 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: splitting on spaces
Message-Id: <MPG.13efadab13fa1c8698ac14@nntp.hpl.hp.com>

In article <8m4r22$hjg$1@nnrp1.deja.com> on Mon, 31 Jul 2000 21:28:40 
GMT, Rodney Engdahl <red_orc@my-deja.com> says...
> In article <8m4h6h$9ig$1@nnrp1.deja.com>,
>   emavres@my-deja.com wrote:
> > Can anyone show me how to split a line that is seperated by spaces but
> > not by the same amount of spaces?
> >
> > Example:
> >
> > "Hello how can    I       help  you"
> >
> > I would like to get each word.
> 
> you might want to look into regexps to change consecutive spaces into a
> single space, and then look into split to split on a space.

That certainly is the long way around.  Either (as others have said) 
split on /\s+/ (which preserves a leading null field) or on " ", which 
doesn't.

perldoc -f split.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 31 Jul 2000 21:56:43 GMT
From: bardicstorm@my-deja.com
Subject: Re: Syntax Question
Message-Id: <8m4smq$iud$1@nnrp1.deja.com>


> Line-by-line processing is generally preferred, as it conserves
memory.

Actually, there is a good reason I need to get the whole file all at
once...  But thanks for the advice on mem..

> But if you insist:
>
> #!/usr/local/bin/perl -w
> use strict;
>
> my $file = 'somefile.txt';
> my $file_contents;
>
> {
>     local $/ = undef; # Turn on slurp mode
>     open FH, $file or die "Could not open $file: $!\n";
>     $file_contents = <FH>;
> }
>
> The enclosing block is just to limit the change to $/ (the
> INPUT_RECORD_SEPERATOR) to the one file read and to not make it global
> to the entire program.

Thanks for the answer :)


> Then please do yourself (and all of us) a favor by familiarizing
> yourself with the resources available to you. The first is a utility
> called 'perldoc' that came as part of your Perl distribution. Go to a
> command line and type the following:
>
> perldoc perldoc
> perldoc perl
> perldoc perltoc
>
> Those should get you started. Perldoc contains all the standard
> documentation, FAQs, and even a couple tutorials. It should be the
first
> place you turn with questions. Why? Because most of the questions you
> (as a newbie) are likely to come up with have been asked and answered
a
> thousand times. The docs contain quick, handy, and *correct* answers.
> Posts to Usenet are slower and more error-prone.

Again, thanks, though having looked through the Perldoc and seeing
entries on everything in perl with very little to tell me where to look
for my particular question  (I was looking for some Perldoc related to
files, not figuring the answer would be in the variables)


> Next, if you've RTFM (Read The F*ing Manual) and checked the FAQ, and
> you still can't find an answer, post here. There are some general
> conventions on posting. Following them will improve your results and
> save you the cost of asbestos pants:
>
> * Have a meaningful subject. Things like "Help!" and "Perl question"
>   are not meaningful and will largely be ignored.
> * If possible, include a short snippet of code which exhibits the
>   problem you're having.
> * When responding to a post, place your comments *after* quoted text,
>   and quote only the things you're responding to.
>
> In your case "Sytax Question" is a little vague. "How do I slurp a
> file?" would be clearest to the locals here, but if you're not
familiar
> with that lingo, something like "How do I read an entire file into a
> string?" would work just fine.
>
> Enjoy...
>
> -mjc

Well, my thanks on the posting *advice* and though something may have
been posted a thousand times before, there are likely many hundreds of
new posters every day and while the perldocs do give the *right* answer
posting here gives one thing that the perldocs can not give - namely
varieties of answers..  but thanks to everyone who helped...


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


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

Date: 31 Jul 2000 22:20:21 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Syntax Question
Message-Id: <8m4u35$5mcr3$9@ID-24002.news.cis.dfn.de>

hi,
bardicstorm@my-deja.com wrote:
> I have to admit I don't quite understand this solution..  what does the
> ### my $contents = do { local $/; <FILE> }; ###
> line do?

>>     open FILE, $file or die "$0: open $file: $!";
>>     my $contents = do { local $/; <FILE> };
>>     close FILE;

i'll give it a shot.
do {}
runs the code in between the {} and returns the last evaluated
$variable/code.
do {           # beginning of do
 local $/;     # it sets $/ to undef locally
 <FILE>        # the whole FILE is read.
}              # exit of the do block and returning
               # the last evaluated code which is <FILE>

you may want to look at
perldoc -f do

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please no answers via email unless followup is set to poster.


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

Date: Mon, 31 Jul 2000 16:44:56 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Syntax Question
Message-Id: <MPG.13efaf50426d2dcd98ac15@nntp.hpl.hp.com>

In article <sobr33jt55142@corp.supernews.com> on Mon, 31 Jul 2000 
21:15:15 GMT, Greg Bacon <gbacon@HiWAAY.net> says...
> In article <8m4kt3$cnf$1@nnrp1.deja.com>,
>      <bardicstorm@my-deja.com> wrote:
> 
> :   I was just wondering if anyone could help me with the syntax for
> : reading an entire file into a string variable instead of reading in one
> : line at a time and looping through.
> 
>     open FILE, $file or die "$0: open $file: $!";
>     my $contents = do { local $/; <FILE> };
>     close FILE;

Several recent threads have shown that -- despite its elegance -- this 
solution is slower than either doing the localization in a separate 
statement (as others have posted) or (faster yet), using read().

      read FILE, $contents, -s FILE or die ...

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 1 Aug 2000 11:18:50 +1200
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Syntax Question
Message-Id: <8m51h0$92c$1@hermes.nz.eds.com>


bardicstorm@my-deja.com wrote in message <8m4rvr$id6$1@nnrp1.deja.com>...
>
>
>>     open FILE, $file or die "$0: open $file: $!";
>>     my $contents = do { local $/; <FILE> };
>>     close FILE;

>I have to admit I don't quite understand this solution..  what does the
>### my $contents = do { local $/; <FILE> }; ###
>line do?

It essentially the same as the reply from Michael Carman, but just more
condensed:

#!/usr/local/bin/perl -w
use strict;

my $file = 'somefile.txt';
my $file_contents;

{
    local $/ = undef; # Turn on slurp mode
    open FH, $file or die "Could not open $file: $!\n";
    $file_contents = <FH>;
}






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

Date: Tue, 1 Aug 2000 02:17:22 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: text file to html
Message-Id: <Pine.GHP.4.21.0008010204140.11836-100000@hpplus03.cern.ch>

On Mon, 31 Jul 2000, Colin Keith wrote:

> As someone who writes scripts I write them as though it is my file and I 
> know the contents. 

Oh dear.  I would not even trust myself to that extent; and when the 
input comes from elsewhere, good night.

> >asked.  Suppose the text file had been POD, for example[1]
> 
> Yeah, it could already have contained HTML too.

It's not clear whether you understood the point here.  POD also uses
syntax consisting of less-than, letter(s), greater-than.  Point is, if
you're presented with what's defined to be a plaintext file, and asked
to convert it into HTML, then the problem (modulo an issue that you
point out later) is well defined.  Issues of "does this file contain
POD/SGML/texinfo/FORTRAN/whatever" are totally and utterly irrelevant.  
The file has to be processed as _plain_ text, no matter what character
sequences it might contain, and the resulting HTML needs to be the
proper HTML syntax for representing that original plain-text content.
A simple principle, with a rather simple solution.

> Neither does the definition state if it is a unicode text file, in
> which case the character set that should have been returned was
> absent and we both should have failed the test.

You make an excellent point, and one which I had failed to address
directly.  Well spotted.  There are some serious issues in that area.

> suppose a degree of trust was involved that 'text file' means a file without 
> markup, etc. 

Well, "don't do that".

I'm eliding some irrelvant issues which you touched on.  Check the
headers for disclaimer.

all the best



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

Date: Mon, 31 Jul 2000 21:58:21 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: Uploading images via Perl script
Message-Id: <8m4spq$ive$1@nnrp1.deja.com>

In article <8m4m29$dmo$1@nnrp1.deja.com>,
  oliver.arend@gmx.de wrote:
> Hi there,
>
> I guess you've seen the possibility to upload images onto a server via
> a Perl script, e.g. in a discussion forum.
>
> Can anyone give me a script that will do exactly this, w/ explanations
> how it works?
>
> Oliver
>

you could use a search engine with an appropriate search key "file
upload script" on excite.com seems to return likely candidates . . .


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


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

Date: Mon, 31 Jul 2000 18:41:10 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Use MIME *and* specify the mail server
Message-Id: <39860086.B3FCA8D2@attglobal.net>

mfreake@iii.co.uk wrote:
> 
> I'm quite new to Unix mail systems which may be the cause of the
> problem.
> 
> I want to attatch some files to an email *and* specify the mail server
> to be used (mail3.ourdomain.co.uk, for a made up example).

Check out MIME::Lite, whcih can easily do this for you.
(I'd guess MIME::Entity can too, but I've not used it.)

A line like:

MIME::Lite->send('smtp', 'smtp.server.name', Timeout=>60);

will change the default behaviour of the send method.


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

Date: Tue, 01 Aug 2000 00:16:00 GMT
From: abliss@mindspring.com
Subject: Variable Interpolation Woes
Message-Id: <1103_965088960@eratos>

I'm sure this question has been asked before, but I can't seem to 
find the answer in any of the FAQs or DOCs.  I am trying to do 
something like the following:

print 'The error '.$dbh->errmsg().' occured.';

My first instinct was to use a variable-interpolated string, a la

print "The error $dbh->errmsg() occured.";

but this prints the $dbh reference and then the literal '-
>errmsg()'.  Then I tried every permutation of {'s, ('s, etc. that 
I could come up with, and none of them did the desired thing.  The 
best I could find in the DOCs was this section of perlop:

---
Note also that the interpolation code needs to make a decision on
where the interpolated scalar ends.  For instance, whether 
"a $b -> {c}" really means:
  "a " . $b . " -> {c}";
or:
  "a " . $b -> {c};
Most of the time, the longest possible text that does not include
spaces between components and which contains matching braces or
brackets.  because the outcome may be determined by voting based
on heuristic estimators, the result is not strictly predictable.
Fortunately, it's usually correct for ambiguous cases.
---

This has done nothing but confuse me further, as it does not seem 
to be the case at all (not to mention the sketchy sentence 
structure).  Can someone show me how to do this?


Another thing which seems, to me, like it ought to work is this:

$foo = 'bar';
$bar = 'baz';
$bazbar = 'Yay!';

print "${$$foo$foo}";

But that doesn't even compile.  Even when I give explicit 
directions on what order it the variables should be expanded, like 
this:

print "${${${foo}}${foo}}";

It still doesn't go down.  I think I have some kind of basic 
misunderstanding about how this works.  If someone could give me an 
example or two that would clear it up, I'd be very grateful.

Thanks very much for your time.
Adam Bliss




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

Date: 1 Aug 2000 00:41:37 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Variable Interpolation Woes
Message-Id: <8m56c0$5mcr3$16@ID-24002.news.cis.dfn.de>

hi,
abliss@mindspring.com wrote:
> I'm sure this question has been asked before, but I can't seem to 
> find the answer in any of the FAQs or DOCs.  I am trying to do 
> something like the following:

> print 'The error '.$dbh->errmsg().' occured.';

> My first instinct was to use a variable-interpolated string, a la

> print "The error $dbh->errmsg() occured.";

no, if you want to interpolate a function in a string, 
you should do:

> print "The error @{[$dbh->errmsg()]} occured.";

HTH,
tina


-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please no answers via email unless followup is set to poster.


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

Date: Tue, 01 Aug 2000 00:44:41 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Variable Interpolation Woes
Message-Id: <Z3ph5.55571$fR2.538076@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <1103_965088960@eratos>,
	abliss@mindspring.com writes:
> I'm sure this question has been asked before, but I can't seem to 
> find the answer in any of the FAQs or DOCs.  I am trying to do 
> something like the following:
> 
> print 'The error '.$dbh->errmsg().' occured.';
> 
> My first instinct was to use a variable-interpolated string, a la
> 
> print "The error $dbh->errmsg() occured.";
> 
> but this prints the $dbh reference and then the literal '-
>>errmsg()'.  Then I tried every permutation of {'s, ('s, etc. that 
> I could come up with, and none of them did the desired thing.  The 
> best I could find in the DOCs was this section of perlop:

Try perlref:

	Here's a trick for interpolating a subroutine call into a
	string: 

	print "My sub returned @{[mysub(1,2,3)]} that time.\n";

        The way it works is that when the @{...} is seen in the
        double-quoted string, it's evaluated as a block.  The block
        creates a reference to an anonymous array containing the
        results of the call to mysub(1,2,3).  So the whole block
        returns a reference to an array, which is then dereferenced
        by @{...} and stuck into the double-quoted string. This
        chicanery is also useful for arbitrary expressions:

            print "That yields @{[$n + 5]} widgets\n";


-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours! 
  clintp@geeksalad.org         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

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 3865
**************************************


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