[15673] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3086 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 18 11:10:47 2000

Date: Thu, 18 May 2000 08:10:24 -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: <958662624-v9-i3086@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 18 May 2000     Volume: 9 Number: 3086

Today's topics:
    Re: How to COPY a website <alan-silver@prestwich-smile-gemach.freeserve.furryferret.co.uk>
    Re: how to parse HTMLish name="value" pairs (Bart Lateur)
    Re: Initializing variables <dmeyers@panix.com>
    Re: Is my Perl 5.005_03 Compiler broken? (M.J.T. Guy)
    Re: Minivend evil? (Randal L. Schwartz)
    Re: MS Documents to text---help <flavell@mail.cern.ch>
    Re: MS Documents to text---help <iltzu@sci.invalid>
        need advice on strategy... <webmaster@passani.it>
        Newbie question ? <sferrandez@wineandco.com>
    Re: Newbie question ? <bmb@dataserv.libs.uga.edu>
    Re: Numbers module to normalize numbers and/or smooth c <rootbeer@redcat.com>
    Re: Parsing a mail digest <rootbeer@redcat.com>
        perlcc and NT <Derek.Chaloner@racalitsec.com>
    Re: PerlIS printing out header info. (Steve)
        Problem with classes and autoload <mark.anderson@libertymutual.com>
    Re: Problem with classes and autoload nobull@mail.com
    Re: Protecting Source Code? (Bart Lateur)
    Re: Q: Encryption of client - server communication  <rootbeer@redcat.com>
    Re: RE Question (Bart Lateur)
        re-evaluation (newbie) <crips@control.auc.dk>
    Re: re-evaluation (newbie) <christian@fabel.dk>
    Re: re-evaluation (newbie) (Bill Feidt)
    Re: re-evaluation (newbie) <scott@salmon.ltd.uk>
    Re: re-evaluation (newbie) <aqumsieh@hyperchip.com>
    Re: re-evaluation (newbie) <aqumsieh@hyperchip.com>
        Reading a file into a variable... <fati187@home.com>
    Re: Reading a file into a variable... <billy@arnis-bsl.com>
    Re: Reading from file <billy@arnis-bsl.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 18 May 2000 14:42:54 +0100
From: Alan Silver <alan-silver@prestwich-smile-gemach.freeserve.furryferret.co.uk>
Subject: Re: How to COPY a website
Message-Id: <aYHUcUAeN$I5EwOF@prestwich-smile-gemach.freeserve.co.uk>

In article <3922F9E4.5E971812@zaz.com.br>, Mark Holt <null@zaz.com.br>
writes
>Will you please stop lecturing about legal issues

I was not lecturing, I was pointing out a perfectly reasonable legal
comment. If it doesn't apply to you, then fine ignore it. I never said
it applied to you, I asked if you had thought about it. If you have
thought about it and decided that what you are doing is perfectly legal
then fine. I was just pointing out something that very many people
forget.

No need to be so rude about it. I was trying to help.

Suppose you had posted up a message saying you were going to jump off a
cliff. I might reply and point out that you could get hurt. *You* might
know that you were intending to use a parachute, but I wouldn't know as
you hadn't told me. I would be trying to help, just in case you had
missed something obvious (which in this example is very obvious, in the
real discussion above is not so obvious). I would have thought you could
have been a little more polite about replying.

-- 
Alan Silver
Please remove the "furryferret" if replying by e-mail


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

Date: Thu, 18 May 2000 14:24:33 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: how to parse HTMLish name="value" pairs
Message-Id: <3928fce7.25059036@news.skynet.be>

Stefan Rieken wrote:

>Damn! Has then everything been done before?

Well, you could completely disect the non-XS version of the module
HTML::Parser, i.e. version 2.x.

-- 
	Bart.


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

Date: 18 May 2000 10:56:15 -0400
From: David Meyers <dmeyers@panix.com>
Subject: Re: Initializing variables
Message-Id: <yobg0rf52ls.fsf@panix2.panix.com>

Tom Phoenix <rootbeer@redcat.com> writes:

> On Mon, 15 May 2000 jamalone@earthlink.net wrote:
> 
> > The problem is that when I fill in the field on the web page and click
> > submit, it varies as to what output is displayed.  Sometimes it uses
> > values that I entered on a previous submit instead of what I just
> > submited.
> 
> Sounds like sticky fields from the CGI module. Is that it? Cheers!

In particular, take a look at the CGI module docs and check
out the commands like $query->delete_all(), $query->delete('foo'), 
and also the "override" argument for the form field generation
functions.

--d



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

Date: 18 May 2000 13:26:56 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Is my Perl 5.005_03 Compiler broken?
Message-Id: <8g0r30$hmc$1@pegasus.csx.cam.ac.uk>

webqueen, queen of the web  <webqueen@my-deja.com> wrote:
>I had a bug in my code:
>
>   if defined ($s{$_})
>    {print "<tr><td><input type=checkbox name=$_ checked>$sta{id}</td>".
>           "<td>$sta{name}</td></tr>"}
>
>where I'd left the ()'s from around the
>
>    if (expression).

Well, that fragment gives an error for me with perl5.005_03:

% perl5.005_03 -cw
if defined ($s{$_})
    {print "<tr><td><input type=checkbox name=$_ checked>$sta{id}</td>".
           "<td>$sta{name}</td></tr>"}
syntax error at - line 1, near "if defined"
- had compilation errors.


So your problem must be something to do with the context in which that
fragment appears.     Can you post a *complete* example which shows
the behaviour?     Make it as short as you can, of course.


Mike Guy


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

Date: 18 May 2000 07:11:02 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Minivend evil?
Message-Id: <m1zopoc5jd.fsf@halfdome.holdit.com>

>>>>> "John" == John Callender <jbc@west.net> writes:

>> Basically, the scenario that caused it to happen is:
>> 
>> 1.  The user ran install as root.
>> 2.  Ignoring the fact that it was an application and not a
>> module, and ignoring the suggested default, they selected
>> /usr/lib/perl5/site_perl as the installation directory.
>> 3.  They had UNINST=1 set.
>> 
>> So it overwrote modules in that case.

Heh.  That was *me*. :)

I figured, "this is in the CPAN, so it should have a well-behaved
Makefile.PL" and it did not. :) So I raised the alarm, to keep others
from being burned, and it looks like Mike made it "CPAN.pm-proof" just
as I requested.  Cool.

Makefile.PL did *not* provide a "suggested default", by the way.  If
that was in a README, that's too far away when I'm running CPAN.pm.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 18 May 2000 12:24:08 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: MS Documents to text---help
Message-Id: <Pine.GHP.4.21.0005181221590.5629-100000@hpplus01.cern.ch>

On 18 May 2000, Jonathan Stowe wrote:

> [gellyfish@orpheus work]$ strings daspec.doc | more
> 
> Works for me.

[off-topic] With documents created by some versions of Word, that can
reveal some interesting out-takes, that the author thought they had
deleted!

cheers



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

Date: 18 May 2000 13:27:15 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: MS Documents to text---help
Message-Id: <958655928.7106@itz.pp.sci.fi>

In article <8g05vs$bfk$1@orpheus.gellyfish.com>, Jonathan Stowe wrote:
>In comp.lang.perl.misc JB Goss <jgoss@goss-com.com> wrote:
>> I am looking for something simple to strip the crud out of MS documents and
>> just leave the text... any ideas?
>
>[gellyfish@orpheus work]$ strings daspec.doc | more
>Works for me.

I'm not sure which program creates *.wps files, but strings certainly
can't get anything useful out of one.  The following helped, though:

  perl -pe 'tr/\cJ -~\140-\376//cd' <foobar.wps

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla and its pseudonyms - do not feed the troll.



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

Date: Thu, 18 May 2000 13:19:36 +0200
From: webmaster <webmaster@passani.it>
Subject: need advice on strategy...
Message-Id: <3923D1C8.F714B984@passani.it>

Hallo, here is my big problem. I want to code and
deploy some libraries for cross-server web development.

Here are the requirements:

1) I want to be able to develop with scripting.

2) it should be relatively simple to port those libraries to IIS
and Apache out of a unique source code.

3) the libraries will be distributed freely, but I would like
to hide the code in order to enforce respect for the APIs

Initially, I was thinking about JavaScript, VBScript, Windows 
Script Components and COM objects written in VB out of the VBScript
prototype, but this would make point 2) difficult to achieve.

Since I have some experience with Perl from my CGI days, I was wondering
if PerlScript could be an option for satisfying the requirements
above. If the answer is yes, which approach should I follow?

Can I develop with PerlScript/ASP and freeze the code into 
some Perl COM object when I'm satisfied?  How easily could I
port such code to Apache (fast_cgi? plain CGI?)

Thank you

l.


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

Date: Thu, 18 May 2000 15:11:31 +0200
From: Sebastien FERRANDEZ <sferrandez@wineandco.com>
Subject: Newbie question ?
Message-Id: <3923EC03.1DB57467@wineandco.com>

Hi there,

I'm pretty new to perl, in fact I just started 10 mins ago (worked on
PHP for about 10 months).
I've got a function and there's a line I don't really understand :

 $cgi = new CGI(*FILE);

What is that doing ???

sub  pl_opensession($$)
{
    local $cgi;

    my($dir,$sessionid) = @_;
    $filename = "$dir/$sessionid";
    if ((-f $filename) == 1)
    {
 open(FILE, $filename);
 $cgi = new CGI(*FILE);
 close(FILE);
 return $cgi;
    }
    else
    {
 return 0;
    }
}





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

Date: Thu, 18 May 2000 09:56:34 -0400
From: Brad Baxter <bmb@dataserv.libs.uga.edu>
Subject: Re: Newbie question ?
Message-Id: <Pine.GSO.4.21.0005180948130.7562-100000@dataserv.libs.uga.edu>

On Thu, 18 May 2000, Sebastien FERRANDEZ wrote:

> Hi there,
> 
> I'm pretty new to perl, in fact I just started 10 mins ago (worked on
> PHP for about 10 months).
> I've got a function and there's a line I don't really understand :
> 
>  $cgi = new CGI(*FILE);
> 
> What is that doing ???
> 
> sub  pl_opensession($$)
> {
>     local $cgi;
> 
>     my($dir,$sessionid) = @_;
>     $filename = "$dir/$sessionid";
>     if ((-f $filename) == 1)
>     {
>  open(FILE, $filename);
>  $cgi = new CGI(*FILE);
>  close(FILE);
>  return $cgi;
>     }
>     else
>     {
>  return 0;
>     }
> }

It is call the new() method in the CGI.pm module.  The new() method sees
the string 'CGI' as its first parameter and the typeglob *FILE as its
second.  It returns a reference to a CGI object.  This object ($cgi) will
then be used to call other CGI object methods.

This is an ambitious step for a 10 minute old Perl programmer, but you'll
want to read:

perldoc perlref
perldoc perltoot

among others.

-- 
Brad



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

Date: Thu, 18 May 2000 06:51:34 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Numbers module to normalize numbers and/or smooth curves?
Message-Id: <Pine.GSO.4.10.10005180645240.25459-100000@user2.teleport.com>

On Thu, 18 May 2000, Bray Jones wrote:

> I have a large array of numbers that when graphed, looks very
> "jagged". Meaning I can have considerable differences in two numbers
> all through the graph making the lines take sharp turns up and down in
> short time frames.
> 
> Are there any modules to take those numbers and normalize them before
> I graph them to make a smoother curve in the graph?

Do you want Statistics::Cheating? :-)

But I think you want to do some kind of curve fitting to your data, rather
than changing the numbers. Does that get you closer to a solution? Of
course, there are many possible curves you might want. Maybe something in
the Statistics::* section of CPAN would do what you want. Or maybe you'll
need to make Statistics::BogusData after all. :-)

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 18 May 2000 06:58:19 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Parsing a mail digest
Message-Id: <Pine.GSO.4.10.10005180655270.25459-100000@user2.teleport.com>

On 18 May 2000, Bernard El-Hagin wrote:

> Here's what I've got (btw, I'm sure there are modules that do this
> sort of stuff, but I can't use them for this script):

If you can't use modules (and why not?), you _still_ have no excuse for
re-inventing the wheel. Download the module, check its license, and you'll
probably be permitted to incorporate the code into your program without
further difficulties. And wouldn't you rather have something that's
already been debugged and tested?

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 18 May 2000 11:05:21 +0100
From: "Derek Chaloner" <Derek.Chaloner@racalitsec.com>
Subject: perlcc and NT
Message-Id: <3923c07b.0@nnrp1.news.uk.psi.net>

I am using perl 5.6.0 compiled with Visual Studio 6 on an NT4 SP5
workstation.

Some simple perl scripts can be converted into executable files but others
(like that shown below) fail and require a CTRL C to terminate.
I did originally think that it was a globbing problem but the script I
attempted below does not use globbing.

Can anyone help with the pitfalls of compiling scripts on an NT box?

Derek

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


G:\perl>perlcc frprocess.pl

----------------------------------------------------------------------------
----
Compiling frprocess.pl:
----------------------------------------------------------------------------
----
Making C(frprocess.pl.c) for frprocess.pl!
C:\Perl\5.6.0\bin\MSWin32-x86\perl.exe -IC:/Perl/5.6.0/lib/MSWin32-x86 -IC:/
Perl/5.6.0/lib -IC:/Perl/site/5.6.0/lib/MSWin32-x86 -IC:/Perl/site/5.6.0/li
b -I. -MB::Stash -c  frprocess.pl
C:\Perl\5.6.0\bin\MSWin32-x86\perl.exe -IC:/Perl/5.6.0/lib/MSWin32-x86 -IC:/
Perl/5.6.0/lib -IC:/Perl/site/5.6.0/lib/MSWin32-x86 -IC:/Perl/site/5.6.0/li
b -I. -MO=C,-l2000,-umain,-uattributes,-uDB,-uExporter,-uExporter::Heavy,-uW
in32,-uGetopt,-uGetopt::Std,-uCarp frprocess.pl
Starting compile
Walking tree
Exporter saved (it is in Getopt::Std's @ISA)
Prescan
Saving methods
Bootstrap attributes frprocess.pl
Writing output
Loaded B
Loaded IO
Loaded Fcntl
frprocess.pl syntax OK
Compiling C(frprocess) for frprocess.pl!
C:\Perl\5.6.0\bin\MSWin32-x86\perl.exe -IC:/Perl/5.6.0/lib/MSWin32-x86 -IC:/
Perl/5.6.0/lib -IC:/Perl/site/5.6.0/lib/MSWin32-x86 -IC:/Perl/site/5.6.0/li
b -I. C:\TEMP/frprocess.pl.tst
cl -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT   -DPERL_MSVCRT_READFIX  
-Ic:\perl\5.6.0\lib\MSWin32-x86/CORE -o frprocess frprocess.pl.c  /link -no
logo -nodefaultlib -release  -libpath:"c:\perl\5.6.0\lib\MSWin32-x86\CORE"  
-machine:x86 -libpath:c:\perl\5.6.0\lib\MSWin32-x86/CORE c:\perl\5.6.0\lib\
MSWin32-x86\CORE\perl56.lib   oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib msvcrt.lib

Stuck at this point, can only use control C to terminate.





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

Date: Thu, 18 May 2000 13:31:48 GMT
From: stevec@computer-geeks.com (Steve)
Subject: Re: PerlIS printing out header info.
Message-Id: <3923f09f.157937021@news.geeksnet.com>

It is HTTP headers put they actually print out like text on the wb
page?  How can I hide this??

Thanks,

Steve


On Wed, 17 May 2000 14:48:20 -0700, Tom Phoenix <rootbeer@redcat.com>
wrote:

>On Wed, 17 May 2000, Steve wrote:
>
>> When I try to run a perl script on my NT 4.0 SP5 IIS 4.o server with
>> PERLIS, it prints out the header information like "HTTP/1.1 200 OK
>> Date: Wed, xx 2000 20:22:30 GMT Server: Microsoft-IIS/4.0"
>> 
>> How can I turn this of?
>
>It sounds as if you want to make your webserver do something. Perhaps you
>should search for the docs, FAQs, and newsgroups about webservers. But
>those headers sound a lot like HTTP headers; if it didn't output those, it
>wouldn't be a webserver, would it? :-)
>
>-- 
>Tom Phoenix       Perl Training and Hacking       Esperanto
>Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/
>



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: 18 May 2000 11:09:26 GMT
From: "Mark Anderson" <mark.anderson@libertymutual.com>
Subject: Problem with classes and autoload
Message-Id: <01bfc0ba$09a7b8a0$bc15b393@n0003171>

Hello

I am having a problem with AutoLoader with classes. My package is using the
__END__ mechanism with AutoSplitter. 

In my package I am overriding a method in the super class (specified in
ISA). If I place the overrided method before the __END__ it works fine. If
I place it after the __END__ then it calls the method in the super class. I
would have thought that it would have checked the AUTOLOAD for the package
before going through the ISA list to find the method. 

What is the order of evaluation for discovering a method? I would have
assumed it would

1. Check the package.
2. Check the AutoLoad for the package.
3. For each class in ISA, first check the package and then the autoload for
the package.
4. Try the UNIVERSAL object and autoload.

The Programming Perl book says that it checks the package for the class,
then it goes through the ISA, and then it tries the AUTOLOAD. If this is
true then overridden methods in subclasses could never be auto loaded --
since it always checks the ISA first.

What am I missing?

Thanks

Mark Anderson




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

Date: 18 May 2000 13:00:08 +0100
From: nobull@mail.com
Subject: Re: Problem with classes and autoload
Message-Id: <u9snvgkr07.fsf@wcl-l.bham.ac.uk>

"Mark Anderson" <mark.anderson@libertymutual.com> writes:

> The Programming Perl book says that it checks the package for the class,
> then it goes through the ISA, and then it tries the AUTOLOAD. If this is
> true then overridden methods in subclasses could never be auto loaded --
> since it always checks the ISA first.
> 
> What am I missing?

Subroutine stubs.

For details: perldoc AutoLoader


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


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

Date: Thu, 18 May 2000 10:32:53 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Protecting Source Code?
Message-Id: <3923c6ba.11189705@news.skynet.be>

James wrote:

>Anyone know any good techniques for protecting your perl code?

I write crappy code. Nobody wants it.

-- 
	Bart.


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

Date: Thu, 18 May 2000 06:40:44 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Q: Encryption of client - server communication 
Message-Id: <Pine.GSO.4.10.10005180639490.25459-100000@user2.teleport.com>

On Wed, 17 May 2000, Thomas Åhlen wrote:

> I wonder which encryption method is best to use when encrypting
> communications between a client and a server.

That sounds like you have a question on encryption methods and their
merits. Perhaps you should search for the docs, FAQs, and newsgroups about
encryption. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 18 May 2000 14:21:36 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: RE Question
Message-Id: <3927fc5a.24917659@news.skynet.be>

>Xah wrote:
>
>>Uri Guttman <uri@sysarch.com> wrote
>>> this is fancy coding?
>>> 
>>> split( /,(?! )/, $line ) ;
>>
>>No, it's mumble jumble very much preferred by fancily-clad yokel like
>>yourself. Godzilla is just too diffident to point that out.
>>
>>Godzilla's suggestion:
>>
>>> Replace comma/space with a special character.
>>> Perform a split.
>>> Replace the comma/space.
>>
>>for the question:
>>
>>>I want to parse lines like this:
>>>"Some text with comma, bad bad",33,44,55
>>>by commas, but not by commas followed by a space.
>>
>>is actually quite elegant and effective.
>

Godzilla! wrote:

>"Ms. Schilitubi, could you talk more plain?
> I can't understand those big words."
>
>As a result of this student's comment, I lowered
>my language level and still maintained encouragement
>for my students to raise their language level.
>
>As this applies to programming, we can write
>very fancy dancy techno-gibberish code and,
>exclude a large percentage of readers from
>understanding what is said.

What is this "mul-ti-pli-ca-tion"? Do you have to use those difficult
words? Why can't you say it in terms that everybody understands? Like
"add"? Look, here's some simple code, which works just nice and dandy.
Furthermore, everybody can understand it.

	$p = 0;
	while($b--) {
	    $p += $a;
	}

What do you mean, it doesn't work for non-integers? What are
"non-integers" anyway? Some more of your fancy words? Why would anybody
in the world ever need them?

There's no need for any mambo-jambo like 

	$p = $a*$b;

Ever. Nobody understands what it means anyway.

-- 
	Bart.


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

Date: Thu, 18 May 2000 13:25:00 GMT
From: Jesper Birkholm Marcher Hansen <crips@control.auc.dk>
Subject: re-evaluation (newbie)
Message-Id: <Pine.GSO.4.10.10005181518200.27583-100000@prosit.control.auc.dk>

Hi! 

Well, I've got a simple question (I hope):

How do I get the following code to print out "test2" when the variable
$number has changed?


$number = 1;

$mystring = "test$number\n";

	print $mystring;	#Prints "test1"

$number = 2;
	print $mystring;	#Prints "test1", but it should "test2"



regards,

Jesper



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

Date: Thu, 18 May 2000 15:38:45 +0200
From: Christian Vandsø <christian@fabel.dk>
Subject: Re: re-evaluation (newbie)
Message-Id: <0cs7is0gcv5q2f7btdbvpb7qkn20nmjp1l@4ax.com>

On Thu, 18 May 2000 13:25:00 GMT, Jesper Birkholm Marcher Hansen
<crips@control.auc.dk> wrote:


>$number = 1;
>
>$mystring = "test$number\n";

 Assign $mystring to the string "test1"
>
>	print $mystring;	#Prints "test1"

 Yes.

>
>$number = 2;
>	print $mystring;	#Prints "test1", but it should "test2"

 No, $mystring is assigned to contain the value test1. You have to
reassign $mystring to reflect the change as you did in $mystring=
"test$number"; 

/Christian


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

Date: Thu, 18 May 2000 13:52:44 GMT
From: wfeidt@cpcug.org (Bill Feidt)
Subject: Re: re-evaluation (newbie)
Message-Id: <8F3869FC4wfeidthiscom@207.126.101.97>

crips@control.auc.dk (Jesper Birkholm Marcher Hansen) wrote in 
<Pine.GSO.4.10.10005181518200.27583-100000@prosit.control.auc.dk>:

>How do I get the following code to print out "test2" when the variable
>$number has changed?
>
>
>$number = 1;
>
>$mystring = "test$number\n";
>
>     print $mystring;     #Prints "test1"
>
>$number = 2;
>     print $mystring;     #Prints "test1", but it should "test2"

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

my $number = 1;
my $string = "test$number\n";
print $string;     #Prints "test1"
$number = 2;
$string = "test$number\n";
print $string;     #Prints "test2"

or perhaps:

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

my $number = 1;
print "test$number\n";
$number = 2;
print "test$number\n";

Regards,

Bill
wfeidt@cpcug.org


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

Date: Thu, 18 May 2000 15:14:49 +0100
From: "Scott Pritchett" <scott@salmon.ltd.uk>
Subject: Re: re-evaluation (newbie)
Message-Id: <8g0tsm$jib$1@lure.pipex.net>

Or :-
$number=1;
$test1="test1";
$test2="test2";
for ($number=1;$number<=2;$number++)
{
    $mystring="test$number";
    print $$mystring;
}

Or something like that.


Scott


"Jesper Birkholm Marcher Hansen" <crips@control.auc.dk> wrote in message
news:Pine.GSO.4.10.10005181518200.27583-100000@prosit.control.auc.dk...
> Hi!
>
> Well, I've got a simple question (I hope):
>
> How do I get the following code to print out "test2" when the variable
> $number has changed?
>
>
> $number = 1;
>
> $mystring = "test$number\n";
>
> print $mystring; #Prints "test1"
>
> $number = 2;
> print $mystring; #Prints "test1", but it should "test2"
>
>
>
> regards,
>
> Jesper
>




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

Date: Thu, 18 May 2000 14:39:32 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: re-evaluation (newbie)
Message-Id: <7a1z2zncrf.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>


"Scott Pritchett" <scott@salmon.ltd.uk> writes:

> Or :-
> $number=1;
> $test1="test1";
> $test2="test2";
> for ($number=1;$number<=2;$number++)
> {
>     $mystring="test$number";
>     print $$mystring;
            ^^
            ^^
> }

$mystring is not a scalar reference. No need for you to dereference it.

--Ala


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

Date: Thu, 18 May 2000 14:56:38 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: re-evaluation (newbie)
Message-Id: <7awvkrlxei.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>


Jesper Birkholm Marcher Hansen <crips@control.auc.dk> writes:

> How do I get the following code to print out "test2" when the variable
> $number has changed?
> 
> 
> $number = 1;
> 
> $mystring = "test$number\n";
> 
> 	print $mystring;	#Prints "test1"
> 
> $number = 2;
> 	print $mystring;	#Prints "test1", but it should "test2"

You can't do it this way because the double quotes in your $string
assignment interpolate the value of the $number scalar. So, after that
statement, you don't really know how your string was constructed.

The simplest solution I can think of is to use a closure:

	use subs qw/mystring/;

	my $number = 1;

	sub mystring { return "test$number" }

	print mystring;

	$number = 2;

	print mystring;
	__END__
	test1
	test2


You can probable also do it with tied variables, but it's a bit more
involved.

--Ala


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

Date: Thu, 18 May 2000 11:03:06 GMT
From: Brian <fati187@home.com>
Subject: Reading a file into a variable...
Message-Id: <958648218.1793676936@news>

Is it possible to simply append information to the end of a variable?  My
problem is that I'm trying to read a file into a variable and then print that
file into another file.  When I tried assigning $var = $_ it printed the lines
in reverse order because it would assign the new value to the front of the
variable instead of the end.  When I tried $var ="$var$_" and $var .= $_ they
both printed duplicate lines (ex. for a 2 line file it would print line1, line2,
line1).  Any suggestions on how I could do this would be appreciated.

Fati


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

Date: Thu, 18 May 2000 12:33:23 GMT
From: Ilja <billy@arnis-bsl.com>
Subject: Re: Reading a file into a variable...
Message-Id: <8g0nui$tq0$1@nnrp1.deja.com>

In article <958648218.1793676936@news>,
  Brian <fati187@home.com> wrote:
> Is it possible to simply append information to the end of a variable?  My
> problem is that I'm trying to read a file into a variable and then print that
> file into another file.  When I tried assigning $var = $_ it printed the lines
> in reverse order because it would assign the new value to the front of the
> variable instead of the end.  When I tried $var ="$var$_" and $var .= $_ they
> both printed duplicate lines (ex. for a 2 line file it would print line1, line2,
> line1).  Any suggestions on how I could do this would be appreciated.
>

I cannot help you with your code because you didn't post one.
Maybe you have are error at line 17 ;-)

So from your posting I guess you need to copy a file.
Some suggestions (not tested):

1. To simply copy a file (without processing):

use File::Copy;

copy ('/path/to/source', '/path/to/dest')   or die "cannot copy: $!\n";

2. If you really need to read the file line by line, do some processing
and put the line into another file then:

# open() INPUT and OUTPUT

while ($line = <INPUT>)
{
     # do something with $line

     print OUTPUT $line;
}

3. Finally, if you really want to read "the whole" file into *one* variable,
then:

{
     local $/ = undef;
     $the_whole_file = <INPUT>;
}

See perldoc perlvar about $/ variable details.
Also consult perldoc perlfaq5.

If you have no local copy, then visit
http://www.cpan.org/doc/manual/html/pod/index.html.

Hope this helps.
Ilja.


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


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

Date: Thu, 18 May 2000 11:02:31 GMT
From: Ilja <billy@arnis-bsl.com>
Subject: Re: Reading from file
Message-Id: <8g0ik0$o1k$1@nnrp1.deja.com>

In article <7ZOU4.120$p57.4213@read2.inet.fi>,
  "Marko Nikulainen" <marko.nikulainen@etela-savo.com> wrote:
> Is this code correct?
>
> #!/usr/bin/perl

#!/usr/bin/perl -w

use strict;
# you'll need 'my' for variables below

> use CGI;
> $query = new CGI;
>
> $user = $query->param('user');
> $password = $query->param('password');
>
> $file = '.passwd';

Use full pathnames. You cannot be sure that '.passwd' resides in script's
current working directory.

> open (PASSWD, $file) or die "Can't open $file. ($!)\n";
> while (<PASSWD>)
> {
> ($loguser, $logpass)= split(":", $_);
> }
> close (PASSWD);

chomp;
($loguser, $logpass) = split /:/;

But now re-think your program's logic: you read from file line by line, split
the line and then you simply discard  the data (overwriting it in next
iteration) !

 ...the rest of code skipped due to errors above...

Good luck.
Ilja.


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


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

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


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