[15441] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2851 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 24 09:05:20 2000

Date: Mon, 24 Apr 2000 06:05:07 -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: <956581507-v9-i2851@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 24 Apr 2000     Volume: 9 Number: 2851

Today's topics:
        Ambiguous Use -> {flock} and {"flock"}? <morbus@disobey.com>
        backslash escaping not metacharacters in a char class <fjhernandez@recol.es>
    Re: call sub from browser jlamport@calarts.edu
    Re: call sub from browser <tmp0001@unixsnedkeren.dk>
    Re: common filehandle to read and write!! <lr@hpl.hp.com>
        Critique My Code <grichards@flashcom.net>
    Re: crypt() not working? gettyman@my-deja.com
    Re: DBD::Sybase and/or freeTDS oddities <fty@mediapulse.com>
    Re: How can I delay "use"ing a module until the module  jlamport@calarts.edu
    Re: How can I delay "use"ing a module until the module  <godzilla@stomp.stomp.tokyo>
    Re: ICQ client <sol@the-funk.net>
        JPEG and GIF MIME type decoding <shout@uk2.co.uk>
    Re: JPEG and GIF MIME type decoding <flavell@mail.cern.ch>
        MHonArc v2.4.6 (Earl Hood)
        Mysterious \n Character. Argh! <morbus@disobey.com>
    Re: Mysterious \n Character. Argh! <morbus@disobey.com>
        newbie: camel vs. llama <jesucristo2@netscape.net>
    Re: Show me if you don't mind <tmp0001@unixsnedkeren.dk>
    Re: subname from subref <joseph.kazimierczyk@bms.com>
        to print a flat data file with a certain lengths ? <koreags@thrunet.com>
    Re: to print a flat data file with a certain lengths ? jlamport@calarts.edu
        URGENT help needed (Lobo)
    Re: URGENT help needed jlamport@calarts.edu
        using CPAN: what's all this junk!? jlamport@calarts.edu
    Re: wierd behaviour untainting... jlamport@calarts.edu
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 24 Apr 2000 07:04:03 -0400
From: Morbus Iff <morbus@disobey.com>
Subject: Ambiguous Use -> {flock} and {"flock"}?
Message-Id: <morbus-82D2F3.07040324042000@news.totalnetnh.net>

Ok. There's a simple explanation for this, I'm sure, but I just can't 
see it. I'm getting an error message under -w about "Ambiguous Use" and 
how {flock} should be {"flock"}.

The warning comes from the following snippet of code, which is located 
in a subroutine:

   flock LOG, 2 if $SETTINGS{flock};

$SETTINGS{flock} is either true or false and is sucked in from a config 
file. Putting quotes around flock makes the warning go away. Why? 
Another thing that confuses me is that I use the "assumed quotes" thingy 
throughout my main program (and other subroutines) without a problem, as 
in:

   if ($SETTINGS{debug}) { 
      &log("**** Starting xxx with debugging. ****");
   }

Any ideas on why this is happening? (If possible, please respond through 
email as well - I'm not a heavy news user). Thanks!

Morbus Iff
http://www.disobey.com/


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

Date: Mon, 24 Apr 2000 12:54:15 +0200
From: Javier Hernandez <fjhernandez@recol.es>
Subject: backslash escaping not metacharacters in a char class
Message-Id: <390427D6.FAA639F7@recol.es>

Hi All,
I have read something about a backslash trying to escape a
non-metacharacter
within a character class [ ... ].

i.e.  A regex like:    /[a-z\:]+/

What will happen with the '\' in that case ?

I understand that the regex will try to match one or more letters, OR
one or more colons, OR ????...
I put that example based on the fact that a colon ':' is not a
metacharacter within a character class.
My understanding is that the only metacharacters within a character
class are: the dash '-' like a range, the leading caret at the begining
like a negated, and the ']' to close the character class.
Please, correct me if I am wrong.

Best regards and thanks in advance,

--
Javi,          _____            fjherna@europa3.com
                 |              http://www.europa3.com/users/fjherna
      \_________(_)_________/   http://www.valux.org/
 ____________!___!___!___________ Valencia
--------------------------------------------------------------------
If you want to read about love and marriage you've got to buy two separate
books.
                -- Alan King





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

Date: Mon, 24 Apr 2000 07:50:47 GMT
From: jlamport@calarts.edu
Subject: Re: call sub from browser
Message-Id: <8e0uck$r17$1@nnrp1.deja.com>

In article <u9vh18n427.fsf@wcl-l.bham.ac.uk>,
  nobull@mail.com wrote:
> dmayo2@yahoo.com writes:
>
> > I was wondering if there is a way to call a subroutine in a perl script
> > directly from the browsers location bar.
>
> Define "directly".
>
> > e.g.
> >
> > /cgi-bin/perlsrcipt.cgi?subroutine3
>
> Obviously a CGI script can choose to interpret the QUERY_STRING in any
> way it likes.
>
> If you want to interpret this as a fuction just do:
>
> use CGI;
> no strict 'refs';
> &{query_string()}();
>
> Note this is a security hole you could drive a truck through - do not
> even consider actually doing this.

Or heck, why muck around with CGI.pm and symbolic references when you
could put it all in one line with

eval $ENV{'QUERY_STRING'};

(WARNING:  This is a JOKE.  If you don't understand why the above code is
an EXTREMELY BAD IDEA, you shouldn't be writing CGI scripts!)

-jason


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


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

Date: Mon, 24 Apr 2000 10:48:39 +0200
From: Thorbjoern Ravn Andersen <tmp0001@unixsnedkeren.dk>
Subject: Re: call sub from browser
Message-Id: <39040A67.35B3F76E@unixsnedkeren.dk>

jlamport@calarts.edu wrote:

> Or heck, why muck around with CGI.pm and symbolic references when you
> could put it all in one line with
> 
> eval $ENV{'QUERY_STRING'};

Hmmm...  How much can you actually do with this?  Lots of characters are
quoted so you cannot do strings for one. 

 ...foo.pl?fork()while(1)

Well, you can always just put the machine down.

> (WARNING:  This is a JOKE.  If you don't understand why the above code is
> an EXTREMELY BAD IDEA, you shouldn't be writing CGI scripts!)

Sissy :-)

-- 
  Thorbjørn Ravn Andersen               "...plus...Tubular Bells!"
  http://www.mip.sdu.dk/~ravn


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

Date: Mon, 24 Apr 2000 00:07:21 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: common filehandle to read and write!!
Message-Id: <MPG.136d9281d0bd99ba98a961@nntp.hpl.hp.com>

In article <8e0o2u$jn1$1@nnrp1.deja.com> on Mon, 24 Apr 2000 06:03:14 
GMT, prakash_ojha@my-deja.com <prakash_ojha@my-deja.com> says...
> is there a common way to create filehandle for both read/append..

Did you ask here before reading any documentation on the 'open' 
function?  That is lazy and rude.

I'll give you the answer, though I'm sure others will think I shouldn't.

    open FILE, '+>>file' or die "Couldn't open 'file'. $!\n";

Now I suggest you read these documents:

    perldoc -f open

    perldoc perlopentut

And think twice before asking a question like that again, without doing 
your homework.

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


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

Date: Mon, 24 Apr 2000 02:58:36 -0700
From: "Gabe" <grichards@flashcom.net>
Subject: Critique My Code
Message-Id: <sg86hhfccdo185@corp.supernews.com>

I'm a relative novice. I've never had any formal programming training, so I
wonder if my programs are just horribly inefficient. I'm looking for
efficiency and style advice. Are there better methods to do what I'm trying
to do?

My code is below.

#!/usr/local/bin/perl
#This program searches a flat-file text database for record matches on
$request and $page.
#The program then displays the thumbnail images the record refers to as a
link to the larger image.

#Standard stuff.
use strict;
use lib '/home/mopicmag/www/modules';
use CGI;

my $cgi = new CGI;

#These variables are what we are searching our database for.
#$request is the name of the event the image is categorized under.
my $request = lc($cgi->param('req'));
#$page is the page on the site we assigned the picture in the database.
my $page = $cgi->param('page');

main: {
&event;
}

#Return images if user is searching by event category (i.e. not a keyword
search).
sub event {

 #The upper template of our standard HTML page.
 print $cgi->header;
 open (HTML, '/home/mopicmag/www/templates/headertemplate1.txt') or die
&error;
 print while (<HTML>);
 close HTML;

 #Some flags I'm going to use.
 my $more = 0;
 my $counter = 0;
 my $counter2 = 0;

 #Open the database file with records of all the images stored on the web
server.
 open (DBASE, '/home/mopicmag/www/picbase/picbase') or die &error;
 my
($picid,$picdes,$path,$eventid,$dir,$eventname,$eventdes,$eventdate,$loc);
 while (<DBASE>) {

($picid,$picdes,$path,$eventid,$dir,$eventname,$eventdes,$eventdate,$loc)=sp
lit("\t", lc($_));

  #If 3 thumbnails have been displayed end this table row and begin a new
one.
  if ($counter == 3)

   #This $counter2 thing is so that if there are ONLY 3 images on this page,
a bunch of empty rows won't be created.
   $counter2++;
   if ($counter2 == 1) { print "</td></tr><tr align=center><td
align=center>";}
  }
  #In case we ever allow more than 5 thumbs per page align them in rows of
3.
  elsif ($counter > 3) {
   if (($counter%3) == 0) { print "</td></tr><tr align=center><td
align=center>";}
  }

  #If $request matches, and there are more "pages" flag $more.
  if ($dir eq $request) {
   if ($loc == ($page+1)) { $more = 1;}
  }

  #If 5 images have printed and there are more pages print the link and exit
the loop.
  if ($counter == 5) {
   if ($more == 1) {
    my $nextpage = ($page + 1);
    print "</td></tr><tr><td align=center><a
href=http://www.mopicmag.com/cgi-bin/findpic.cgi?req=$request&page=$nextpage
>Page $nextpage</a></td>";
    last;
   }
  }

  #If we haven't yet found 5 pictures check if $request and $page match and
if so print the image and link.
  if ($counter <= 4) {
   if ($dir eq $request) {
    if ($page == $loc) {
     my $lnk = "$path.jpg";
     my $img = ($path . 'a' . '.jpg');
     print "<a href=$lnk><img border=0 src=$img></a>\&nbsp\;\&nbsp\;";
     $counter++;
    }
   }
  }

  #If we're at the end of file check whether there are more "pages" in this
category and display the appropriate link.
  if (eof) {
    if ($more == 1) {
     my $nextpage = ($page + 1);
     print "</td></tr><tr><td align=center><a
href=http://www.mopicmag.com/cgi-bin/findpic.cgi?req=$request&page=$nextpage
>Page $nextpage</a></td>";
     last;
    }
    else { print "</td></tr><tr><td align=center><a
href=http://www.mopicmag.com/gallery.html>Back to Gallery</a></td>";}
  }
 }
 close DBASE;

 #The lower template to our standed HTML page.
 open (HTML, '/home/mopicmag/www/templates/footertemplate1.txt') or die
&error;
 print while (<HTML>);
 close HTML;
}

sub error {
 print $cgi->header;
 print $cgi->start_html(-title=>'Error');
 print $cgi->h2("Error Message: $!");
 print $cgi->end_html;
}







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

Date: Mon, 24 Apr 2000 08:42:16 GMT
From: gettyman@my-deja.com
Subject: Re: crypt() not working?
Message-Id: <8e11d7$ts9$1@nnrp1.deja.com>

In article <8dub09$rcb$1@orpheus.gellyfish.com>,
  Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>
> No it isnt something you should have to live with.  If you have
downloaded
> and built and installed libcrypt on your system then you should
reconfigure
> your Perl by running 'sh Configure' in the Perl source distribution
> directory this should result in some lines in config.sh like :
>
> d_crypt='define'
>
> ..
>
> libs='-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt'
> libsdirs=' /usr/lib'
> libsfiles=' libnsl.so libndbm.so libgdbm.so libdb.so libdl.so libm.so
libc.so libposix.a libcrypt.so'
>
libsfound=' /usr/lib/libnsl.so /usr/lib/libndbm.so /usr/lib/libgdbm.so /
usr/lib/libdb.so /usr/lib/libdl.so /usr/lib/libm.so /usr/lib/libc.so /us
r/lib/libposix.a /usr/lib/libcrypt.so'
>
> then when you can run 'make' and you should have a working crypt
function.

I ran Configure again and checked config.sh, the libcrypt stuff is all
there.  After recompiling perl, WebMin still claims that crypt() isn't
working.  I tried the crypt() example that comes with the perl man
pages and that seems to work.  Perhaps I need to post something on the
WebMin mailing list.  Thanks anyway.


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


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

Date: Mon, 24 Apr 2000 07:50:07 -0400
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: DBD::Sybase and/or freeTDS oddities
Message-Id: <8e1cjg$a8s$1@news3.icx.net>


Tom Phoenix <rootbeer@redcat.com> wrote in message
news:Pine.GSO.4.10.10004230811370.25963-100000@user2.teleport.com...
>
> > I find it hard to believe that nobody is using the freeTDS driver with
> > the Sybase.pm module to access MS SQLServer from a Sun box running
> > Solaris 2.8.
>
> That's pretty specific. Are you sure your problem comes up only in that
> configuration?

No, I'm not sure. I only have access to the above system and a PC running
RedHat 6.2. It works beautifully under linux and works with a lot of
indiosyncrasies under solaris. Biggest problem is it hangs on queries
returning only one row. It thinks there is more rows and waits. It also
seems to destroy the array I store the row in when I use
$sth->{syb_more_results} to get past the waiting.

P.S. Sorry for  posting twice to two different NG's. I am just anxious for
an explanation/solution.

jay




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

Date: Mon, 24 Apr 2000 06:55:21 GMT
From: jlamport@calarts.edu
Subject: Re: How can I delay "use"ing a module until the module is needed?
Message-Id: <8e0r4m$msq$1@nnrp1.deja.com>

In article <8e0kbj$g3h$1@nnrp1.deja.com>,
  alexandria_sarkut@my-deja.com wrote:
>
> Technical journal writers should be subject to
> a prerequisite of a degree in English before
> being allowed to contribute technical articles
> for publication.
>
> Documentation for Perl via your reference is
> so poorly written, its readability ranges from
> mis-leading to incomprehensible.
>
> Definition of and agreement upon terms of usage
> for discussion is a must and well abided concept
> amongst trained scientists. In this case, terms
> such as 'evaluated', 'loaded', 'compiled' and
> 'executed' are very poorly used quite often.
>
> A module referenced by a conditional statement
> is not evaluated first at compile time nor is it
> executed until called, save for any initialization
> code which may or may not be present. A module is
> loaded into memory as a 'sub-routine' in a general
> sense. It is present, basically as ascii code until
> executed by direct call. It is not pulled into memory
> until a portion of a script is read containing a
> reference. This reference may fall anywhere within
> a script and a module will be evaluated when this
> reference is read, quite contrary to previous claims
> of a module being evaluated before any other coding.
>
> This term "evaluation" does apply in the sense of
> checking for usual syntax errors, format errors,
> just as all code is upon compile, but without
> execution of any sort, dismissing initialization
> when present.
>
> A point was made in this thread regarding a
> difference between behaviors of "require" and
> of "use" which, in general, are correctly
> worded and understandable. However, some have
> suggested a module, such as LWP, is "executed"
> first before anything else within a program.
> This is quite inaccurate as a result of sloppy
> wording and poor use of technical terms.
>
> A statement is made:
>
> " Perhaps you were thinking of:
>
>          eval 'use Package';
>
>  which while being useful from the perspective of deferring the use
>  until runtime, also fails to do the import until runtime, so
>  prototypes and bareword-subroutines will fail.  As long as you're
>  going that far, I'd suggest this:
>
>          if ($some_condition) {
>                  require Package...."
>
> As you can clearly read, it is said "deferring the use until...."
> which is immediately qualified by contrast of "...do the import...."
> This author is stating a module is "executed" ("...the use....")
> before any other code is executed. I disagree.
>
> You have stated,
>
> "Whatever is in the BEGIN block (_regardless_ of where
>  the BEGIN block appears in your code) executes before
>  everything else...."
>
> I also disagree with this statement along with previous
> statements of this nature posted within this thread.
>
> A module is not executed until it is called, regardless
> where a call is located within a script. This is quite
> in evidence of my example of a LWP call. If a conditional
> statement is not passed, not met, a LWP module is never
> executed although present as a "sub-routine" within memory.

Actually, the code within a module *is* executed as soon as the compiler
gets to the use statement that refers to it.

A simple test example:

create a file "bar.pm", containing:

package bar;
print "bar\n";

now create a file "foo.pl", containing:

print "foo\n";
use bar;

now at the shell, type "perl foo.pl", and your output will be:

bar
foo

Same thing if we change "foo.pl" to:

print "foo\n";
if (0) {
	use bar;
}

The code within bar.pm is *executed* (not just compiled, as you seem to
be implying) before the code in foo.pl.

> These claims a module is executed regardless, are simply
> not accurate. However, I suspect these claims appear as
> such because of difficulties in correct usage of technical
> terms in discussion and within documentation.

Assuming that by "module" you mean the code within the .pm file, then the
claims *are* accurate.  But perhaps you're using some definition of
"module" which is just too technical for the rest of us to follow ;)

-jason


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


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

Date: Mon, 24 Apr 2000 02:34:19 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: How can I delay "use"ing a module until the module is needed?
Message-Id: <3904151B.9E90E593@stomp.stomp.tokyo>

Larry Rosler wrote:
 
> In article <8e0kbj$g3h$1@nnrp1.deja.com> on Mon, 24 Apr 2000 04:59:37
> GMT, alexandria_sarkut@my-deja.com <alexandria_sarkut@my-deja.com>
> says...

(snipped with a laugh)


> It takes about two minutes of coding to put all your blather into place.

> It is too bad that you make assertions here which are provably wrong
> with minimal effort.







#!/usr/local/bin/perl


print "Content-Type: text/plain\n\n";


print "TEST ONE: \n\n";

print "This is a test print to confirm execution. \n\n";


print "TEST TWO: \n\n";

$test = "fubar";

if ($test eq "not_fubar")
 {
  use LWP::Simple;
  $test_lwp = get ("http://www.dalmatia.net/lupic/asimov.htm");
  print "LWP has been executed. Results: $test_lwp \n\n";
 }


## Redundancy Test:

if ($test_lwp)
 {
  print " LWP has been executed. Results: $test_lwp \n\n";
 }
else
 {
  print "LWP has not been executed. \n\n";
 }


print "TEST THREE: \n\n";

if (!($test_lwp))
 { 
  print "
   LWP has not been \"executed\" as many claim it would be.

   This is what happens when you don't pay attention to
   wording or don't pay attention to what you are saying.


   \"These claims a module is executed regardless, are simply
    not accurate. However, I suspect these claims appear as
    such because of difficulties in correct usage of technical
    terms in discussion and within documentation. Quite contrary
    to a claim of one I do not understand what is being said,
    I understand all too well; quite often what is said, is
    poorly worded, misleading and, at times, unreadable.\"




   * Enjoys a good laugh *

   Thank you my dear professor in colleague!


   Godzilla!";
 }

exit;



===========================

PRINTED RESULTS:



TEST ONE: 

This is a test print to confirm execution. 

TEST TWO: 

LWP has not been executed. 

TEST THREE: 


   LWP has not been "executed" as many claim it would be.

   This is what happens when you don't pay attention to
   wording or don't pay attention to what you are saying.


   "These claims a module is executed regardless, are simply
    not accurate. However, I suspect these claims appear as
    such because of difficulties in correct usage of technical
    terms in discussion and within documentation. Quite contrary
    to a claim of one I do not understand what is being said,
    I understand all too well; quite often what is said, is
    poorly worded, misleading and, at times, unreadable."




   * Enjoys a good laugh *

   Thank you my dear professor in colleague!


   Godzilla!


===========================



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

Date: Mon, 24 Apr 2000 12:51:43 GMT
From: Sol .................................... <sol@the-funk.net>
Subject: Re: ICQ client
Message-Id: <8e1g0r$c7v$1@nnrp1.deja.com>

http://filewatcher.org/sec/perl-net-icq.html

havent tried it yet. but i will.


In article <8e0mpu$9hc$1@relay-2.energy.gov.ua>,
  "Yaroslav F. Vishnevsky" <rick@zt.energy.gov.ua> wrote:
> > >     Is there a possibility to write a ICQ client with perl?
> >
> > It's been done.
>
> Where?
>
>

--
-----------------------------------------
sol@the-funk.net
http://the-funk.net


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


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

Date: Mon, 24 Apr 2000 11:21:42 +0100
From: Nadja Herkova <shout@uk2.co.uk>
Subject: JPEG and GIF MIME type decoding
Message-Id: <39042035.1BE4E68C@uk2.net>

I've written a Perl program which allows user to upload a JPEG or GIF
file through a web page form.  I've got the upload working but as a
final operation, I am trying to find out a way of reading the size in
pixels of the image from the encoded data.. has anyone any references
that would help me extract this data ?

many thanks
Nadja



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

Date: Mon, 24 Apr 2000 13:52:24 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: JPEG and GIF MIME type decoding
Message-Id: <Pine.GHP.4.21.0004241326300.16623-100000@hpplus01.cern.ch>

On Mon, 24 Apr 2000, Nadja Herkova wrote:

> I am trying to find out a way of reading the size in
> pixels of the image from the encoded data..

Well, it took me some tens of seconds to call up http://www.cpan.org , 
select the "Graphics" category and see a short list that included
Image::Size :

  Currently, Image::Size can size images in XPM, XBM, GIF, JPEG, PNG,
  TIFF and the PPM family of formats (PPM/PGM/PBM).

> has anyone any references

FAQ!  I recommend using the obvious sources of information first, and
only asking questions of the world-wide usenet community when there
are real problems.  It's not as if CPAN is some kind of secret hoard
known only to wizards and cognoscenti:

=head1 Found in /usr/local/lib/perl5/5.00503/pod/perlfaq2.pod

=head2 What modules and extensions are available for Perl?  What is
CPAN?  What does CPAN/src/... mean?





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

Date: 24 Apr 2000 08:45:49 GMT
From: ehood@medusa.acs.uci.edu (Earl Hood)
Subject: MHonArc v2.4.6
Message-Id: <X5YM4.7617$18.9950315@news-east.usenetserver.com>
Keywords: Perl, mail, MIME, HTML

v2.4.6 is now available for download from
<http://www.mhonarc.org>,
<http://www.oac.uci.edu/indiv/ehood/mhonarc.html> and
<http://www.perl.com/CPAN/authors/id/EHOOD/>.

MHonArc is a Perl mail-to-HTML converter. MHonArc provides HTML mail
archiving with index, mail thread linking, etc; plus other capabilities
including support for MIME and powerful user customization features
MHonArc is known to run under a variety of operating systems.
Perl version 5.005, or later, is recommended.

The last announcement made to clpa was for v2.4.0.  Several
enhancments and bug fixes have been made since then.  Check the
above URLs to get list the changes and bug fixes.

To receive an announcement for any new release of MHonArc, subscribe
to the MHonArc mailing list.  Information on how to subscribe is
included in the MHonArc documentation.

	--ewh
-- 
             Earl Hood              | University of California: Irvine
      ehood@medusa.acs.uci.edu      |      Electronic Loiterer
http://www.oac.uci.edu/indiv/ehood/ | Dabbler of SGML/WWW/Perl/MIME




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

Date: Mon, 24 Apr 2000 08:14:24 -0400
From: Morbus Iff <morbus@disobey.com>
Subject: Mysterious \n Character. Argh!
Message-Id: <morbus-16D3B9.08142424042000@news.totalnetnh.net>

I've looked this over a kazillion times, and know what's causing the 
problem, but not why, or even better, how to solve it. 

I'm working with a |%| delimited cache file which, when updates are 
needed, is sliced and diced to only update the necessary parts. Relevant 
code for slicing is below (assume single lines - code has been munged to 
fit within 80 chars.):


  open(AREASCACHE, "$SETTINGS{file_areascache}");
  @line = <AREASCACHE>; close(AREASCACHE);

  foreach $line (@line) {
  ($areas_file, $modtime, $room, $north, $south, $east, $west, 
   $northeast, $northwest, $southeast, $southwest, $up, $down) = 
   split(/\|\%\|/, $line);
         
  $line =~ s/^\n//isg;
             
  if ($CHECKEDAREASCACHE{$areas_file}) { next; }       
  elsif ((stat($SETTINGS{dir_areas} . $areas_file))[9] == $modtime) {
     $CHECKEDAREASCACHE{$areas_file} = 1; next; 
  }
  else { $NEEDSREFRESHING{$areas_file} = 1; $line = ""; }        
  
  }  

    
  open (NEW_AREASCACHE, ">$SETTINGS{file_areascache}");
  print NEW_AREASCACHE @line;


This opens the cache file, does a stat on the modification time of the 
real file and compares the cache modtime. If they're different, then 
we've got to update the damn thing, and all relevant lines that need to 
be updated are "removed" by making that $line blank and then rewriting 
the file.

You'll notice a blank line removing regexp. This is actually to 
partially cure some of the problem I've been running into. It shouldn't 
be there.

Anyways, my cache updating code is below, truncated (again, assume 
single lines):


foreach $areas_file (sort keys(%NEEDSREFRESHING)) {
   $refreshed_areas_file = $SETTINGS{dir_areas} . $areas_file;
   $modtime = (stat($refreshed_areas_file))[9];

   open(REFRESH, $refreshed_areas_file);
      while (<REFRESH>) { 
      &parse_config;
      if ($variable eq "begin-room") { $room = "$value"; next; }
      if ($variable eq "north") { $north = "$value"; next; }
      if ($variable eq "south") { $south = "$value"; next; }
      if ($variable eq "east") { $east = "$value"; next; }
      if ($variable eq "west") { $west = "$value"; next; }
      if ($variable eq "northeast") { $northeast = "$value"; next; }
      if ($variable eq "northwest") { $northwest = "$value"; next; }
      if ($variable eq "southeast") { $southeast = "$value"; next; }
      if ($variable eq "southwest") { $southwest = "$value"; next; }
      if ($variable eq "up") { $up = "$value"; next; }
      if ($variable eq "down") { $down = "$value"; next; }
      if ($variable eq "end-room") { 
         print NEW_AREASCACHE 
"$areas_file|%|$modtime|%|$room|%|$north|%|$south|%|$east|%|$west|%|$nort
heast|%|$northwest|%|$southeast|%|$southwest|%|$up|%|$down\n";
               $room = ''; $north = ''; $south = ''; $east = '';
               $west = ''; $northeast = ''; $northwest = ''; 
               $southeast = ''; $southwest = ''; $up = ''; $down = '';
               $numrooms++; next;
       }
    }   
}


Seems all dandy, eh? This is the problem. $down will get a newline 
character the first time the "print NEW_AREASCACHE" line is run. Or 
perhaps earlier. All I know is that the first new/updated cache line in 
my cache file will contain two new lines (thus the \n removing regexp in 
the first code block above).

I have no clue whats happening here. Coincidentally, if I:

   $down = '';

before the open(REFRESH), then everything works perfectly.

What's happening, and why is it happening? The code runs cleanly under 
-w and use strict; so there's no help there... If possible, please 
respond via email as well, as I'm not a heavy news user. Thanks for any 
help!

Morbus Iff
http://www.disobey.com/


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

Date: Mon, 24 Apr 2000 08:56:18 -0400
From: Morbus Iff <morbus@disobey.com>
Subject: Re: Mysterious \n Character. Argh!
Message-Id: <morbus-BAB220.08561824042000@news.totalnetnh.net>

Welp, I just solved my own problem. Basically, in the first code block, 
$down was being given the \n character when the value didn't exist, 
since it was the last thingy on the line.

When I printed the new entry for the first time, before I blanked out 
$down, it printed out the left-over \n from the $down in the first code 
block.

Is it a matter of principle to chop($line) whether you're expecting a 
newline or not?


FIRST CODE BLOCK
>   foreach $line (@line) {
>   ($areas_file, $modtime, $room, $north, $south, $east, $west, 
>    $northeast, $northwest, $southeast, $southwest, $up, $down) = 
>    split(/\|\%\|/, $line);

SECOND CODE BLOCK
>         print NEW_AREASCACHE 
> "$areas_file|%|$modtime|%|$room|%|$north|%|$south|%|$east|%|$west|%|$nort
> heast|%|$northwest|%|$southeast|%|$southwest|%|$up|%|$down\n";


Morbus Iff
http://www.disobey.com/


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

Date: Mon, 24 Apr 2000 08:05:52 GMT
From: octinomos endemoniado <jesucristo2@netscape.net>
Subject: newbie: camel vs. llama
Message-Id: <8e0v8q$rsp$1@nnrp1.deja.com>

i heard the camel and llama books were pretty good
by christiansen...  if so, which one should i start
with, what's the difference, why is the camel one
more expensive...  any info appreciated...

jesus christ II

                      Esoterick : Linkz
                 http://dennes.freeshell.org

_________________________________________________


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


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

Date: Mon, 24 Apr 2000 09:41:52 +0200
From: Thorbjoern Ravn Andersen <tmp0001@unixsnedkeren.dk>
Subject: Re: Show me if you don't mind
Message-Id: <3903FAC0.E6835112@unixsnedkeren.dk>

RMB wrote:

> For you seasoned Perl programmers, I had a question. Could you send me some
> of your code and a description of what it does? I would like to see what
> nicely written Perl script looks like.

You might find the large number of modules which came with perl for your
platform suitable for this purpose.  If that is not enough, locate an
interesting package at www.cpan.org, download it, and look inside.  


> Just email it to me at rmb34@mindspring.com

No.

-- 
  Thorbjørn Ravn Andersen               "...plus...Tubular Bells!"
  http://www.mip.sdu.dk/~ravn


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

Date: Mon, 24 Apr 2000 08:39:28 -0400
From: Joe Kazimierczyk <joseph.kazimierczyk@bms.com>
Subject: Re: subname from subref
Message-Id: <39044080.4CB8FAFA@bms.com>

nobull@mail.com wrote:

> Joe Kazimierczyk <joseph.kazimierczyk@bms.com> writes:
>
> > Is there a way to get a subroutine's name from it's symbolic reference?
>
> Is this a trick question?  A _symbolic_ reference _is_ the name.  Do
> you perhaps mean _hard_ reference?
>
> Start at %main:: and travese down all the symbol tables to find all
> subroutines then build a hash relating coderef to subroutine names.
> ...

Opps!  Not a trick question, just a badly worded one.  Thanks for the code!

Is there any advantage to using symbolic vs hard references?  What I have in my program is a sub
that acts as wrapper around other subs, taking care of multiple retries until the sub succeeds, and
some notification if a threshold is reached.  The sub name gets used in the notification part.  The
'wrapper' could take either a hard reference or symbolic reference as it's argument - I'm not sure
if there are pros or cons to either approach, except that it's a little more work to get the name
from a hard reference.




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

Date: Mon, 24 Apr 2000 16:32:05 +0900
From: "Joe" <koreags@thrunet.com>
Subject: to print a flat data file with a certain lengths ?
Message-Id: <9qelt5br$GA.281@news.thrunet.com>

Hi,
I would like to print a flat data file with a certain lengths.

We guess we try to print the following line.
print FILE "$a1|$a2|$a3\n";
The maxlength of each value should be 100 or something else.

If the real text length of $a1 is smaller than 100, how to I leave the blank
text space until to be before print |$a2 ?
I mean it should be printed like the following;
aaaaaaaa blank spaces|$a2|$a3
or,
blank spaces aaaaaaaa|$a2|$a3

If the length of $a1 is 40, the blank spaces should 60, than starting to
print nest value.

If someone know about this, Please direct me.
Thanks.









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

Date: Mon, 24 Apr 2000 08:43:48 GMT
From: jlamport@calarts.edu
Subject: Re: to print a flat data file with a certain lengths ?
Message-Id: <8e11g3$tsd$1@nnrp1.deja.com>

In article <9qelt5br$GA.281@news.thrunet.com>,
  "Joe" <koreags@thrunet.com> wrote:
> Hi,
> I would like to print a flat data file with a certain lengths.
>
> We guess we try to print the following line.
> print FILE "$a1|$a2|$a3\n";
> The maxlength of each value should be 100 or something else.
>
> If the real text length of $a1 is smaller than 100, how to I leave the blank
> text space until to be before print |$a2 ?
> I mean it should be printed like the following;
> aaaaaaaa blank spaces|$a2|$a3
> or,
> blank spaces aaaaaaaa|$a2|$a3
>
> If the length of $a1 is 40, the blank spaces should 60, than starting to
> print nest value.
>
> If someone know about this, Please direct me.
> Thanks.

You could try:

$padded_a1 = $a1 . ( ' ' x (100-length($a1)) );
$padded_a2 = $a2 . ( ' ' x (100-length($a2)) );
$padded_a3 = $a3 . ( ' ' x (100-length($a3)) );
print FILE "$padded_a1|$padded_a2|padded_$a3\n";

or for a slightly more elegant solution:

my $FIELD_LENGTH = 100;

sub padList {
	my @returnlist;
	foreach (@_) {
		shift (@return_list, $_ . ( ' ' x ($FIELD_LENGTH-length($_)) );
	}
	return @returnlist;
}

print FILE join('|',padList($a1, $a2, $a3))."\n";

Hope this helps.

-jason


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


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

Date: Mon, 24 Apr 2000 07:15:45 GMT
From: er@matrix.com.br (Lobo)
Subject: URGENT help needed
Message-Id: <3903f296.11832126@news.matrix.com.br>

Hi there.

I'm trying to open a .shtml file from a perl script. The filename come
from a form, like this:

<input type="hidden" name="file" value="foo">

so the script does this:

$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);
foreach $item(@pairs) {
($key,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content=~ s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}

$page = $fields{'file'}.".shtml";
$txt = $fields{'file'}.".txt";

$pagefull = "/usr/home/httpd/html/leiloes/show/".$page;

$txtfull = "/usr/home/httpd/html/leiloes/show/".$txt;


open (HTM, '+>$pagefull');

print HTM "<html>
<head>
<title></title>
</head>
<body>
<!--#include file=\"$txt\" -->
</body>
</html>";
close (HTM);

I'm getting an Internal Server Error, and I think it's beacuse I
didn't sepecified the Content of the output, like 'print
"Content-type:text/html\n\n";'

The thing is that since I'm trying to open a SHTML file, if I put the
text/html it doesn't work - it doesn't show the contents of 'foo.txt'.
Is there a Content-type for SHTML? I've tryed "text/shtml" but it
doesn't work...

BTW, this txt file is CSV (Comma Sparated Values) format, so how can I
make the script to dosn't show the commas?

Oh yes, this cgi is called by the GET method, as you must noticed.

Please HELP ME!




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

Date: Mon, 24 Apr 2000 08:27:07 GMT
From: jlamport@calarts.edu
Subject: Re: URGENT help needed
Message-Id: <8e10gh$t8c$1@nnrp1.deja.com>

In article <3903f296.11832126@news.matrix.com.br>,
  er@matrix.com.br (Lobo) wrote:
> Hi there.
>
> I'm trying to open a .shtml file from a perl script. The filename come
> from a form, like this:
>
> <input type="hidden" name="file" value="foo">
>
> so the script does this:
>
> $temp=$ENV{'QUERY_STRING'};
> @pairs=split(/&/,$temp);
> foreach $item(@pairs) {
> ($key,$content)=split (/=/,$item,2);
> $content=~tr/+/ /;
> $content=~ s/%(..)/pack("c",hex($1))/ge;
> $fields{$key}=$content;
> }
>
> $page = $fields{'file'}.".shtml";
> $txt = $fields{'file'}.".txt";
>
> $pagefull = "/usr/home/httpd/html/leiloes/show/".$page;
>
> $txtfull = "/usr/home/httpd/html/leiloes/show/".$txt;
>
> open (HTM, '+>$pagefull');
>
> print HTM "<html>
> <head>
> <title></title>
> </head>
> <body>
> <!--#include file=\"$txt\" -->
> </body>
> </html>";
> close (HTM);
>
> I'm getting an Internal Server Error, and I think it's beacuse I
> didn't sepecified the Content of the output, like 'print
> "Content-type:text/html\n\n";'
>
> The thing is that since I'm trying to open a SHTML file, if I put the
> text/html it doesn't work - it doesn't show the contents of 'foo.txt'.
> Is there a Content-type for SHTML? I've tryed "text/shtml" but it
> doesn't work...
>
> BTW, this txt file is CSV (Comma Sparated Values) format, so how can I
> make the script to dosn't show the commas?
>
> Oh yes, this cgi is called by the GET method, as you must noticed.
>
> Please HELP ME!

First, in the code you've given, you never actually send *anything* to
the browser.  You're writing to a local file, but not sending anything to
STDOUT. (Also, you're writing to a local file called *literally*
'$pagefull' -- variables don't interpolate when you use single-quotes.)

Second, why are you going to all the trouble to write a CGI script if you
expect the processing to be done using server-side includes?  Why not
just do the include yourself, like this:

open (TXT, $txtfull) || die "couldn't open $txtfull: $!";
undef $/;
$textfile = <TXT>;
close TXT;
print <<"__END_HTML__";
Content-type: text/html

<html>
<head>
<title></title>
</head>
<body>
$textfile
</body>
</html>
__END_HTML__

Or is the idea that you want the script to build an archive of .shtml
files, so that in the *future* you can link directly to the files rather
than accessing them through the script?  In that case, you could write
out the .shtml file the way you do above, and then do

print "Location: http://your.server.net/leiloes/show/$page\n\n";

to redirect the browser to the .shtml file you've just written.

But I have a feeling you haven't thought this through very carefully,
since I doubt that simply including a CSV text file (using shtml or not,
and whether or not you remove the commas) is really going to format the
way you want it to.

Might I suggest you get yourself a good introductory book on Perl, and
maybe another one on HTML?  No offense, but it's pretty obvious from your
code that you don't quite know what you're doing.  :)

-jason


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


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

Date: Mon, 24 Apr 2000 07:15:31 GMT
From: jlamport@calarts.edu
Subject: using CPAN: what's all this junk!?
Message-Id: <8e0sac$o17$1@nnrp1.deja.com>

Sorry, this is probably kind of a dumb newbie question, but here goes:

I just used CPAN for the first time.  It seems to have worked, but now I
want to know: what are all of these extra files and directories that got
installed along with the .pm files?  Which of them are necessary to use
the modules I installed, and which of them can I safely delete?  Is this
documented anywhere?

For what it's worth, I was using the interactive mode (typing
perl -MCPAN -e shell;
from the shell) to install IO::Stringy.

-jason


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


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

Date: Mon, 24 Apr 2000 07:34:36 GMT
From: jlamport@calarts.edu
Subject: Re: wierd behaviour untainting...
Message-Id: <8e0tec$q50$1@nnrp1.deja.com>

In article <8e0lnf$qo7$1@mawar.singnet.com.sg>,
  mathias@singnet.com.sg wrote:
> I have a function which starts like this:
>
> sub provision {
>         print "##1 @_ <BR>";
>         my($server,$domain,$alias,$target) = @_;
>         my($ssh_str);
>
>         print "##2 $server:$domain:$alias:$target <BR>\n" if $debug;
>         # untaint
>         $server =~ /^([\w.]*)$/;
>         $server = $1;
>         $domain =~ /^([\w.]*)$/;
>         $domain = $1;
>         $alias  =~ /^([\w.]*)$/;
>         $alias  = $1;
>         $target =~ /^([\w.]*)$/;
>         $target = $1;
>
>         print "###3 $server:$domain:$alias:$target <BR>\n" if $debug;
>
> 	[...]
>
> whose output when called is this:
>
> ##1 heleconia abc myself abc@def
> ##2 heleconia:abc:myself:abc@def
> ##3 heleconia:abc:myself:myself
>
> I have no clue why that last parameter (target) gets replaced with the
> previous one during the untainting..
>
> WOuld anyone be able to enlighten me?
>
> (I guess it must be very obvious and normal, but I've been staring at it for
> hours now w/o a solution :-(
>
> any help is appreciated...
>

Hint: if you changed

$target =~ /^([\w.]*)$/;

to

$target =~ /^([\w.]*)$/ or die;

guess what would happen?  :)


The symbol '@' isn't a \w nor is it a '.' so 'abc@def' does *not* match
the regexp /^([\w.]*)$/ , thus

$target = $1;

replaces $target with the $1 from the last *successful* pattern match,
which in this case happened to be:

$alias  =~ /^([\w.]*)$/;

Get it now?

-jason


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


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