[15442] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2852 Volume: 9

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

Date: Mon, 24 Apr 2000 11:05:13 -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: <956599512-v9-i2852@ruby.oce.orst.edu>
Content-Type: text

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

Today's topics:
        Aborting a cycling batch program in Perl iforsyth@my-deja.com
    Re: Ambiguous Use -> {flock} and {"flock"}? (Greg Bacon)
        ANN: Outlook Express mbx  -> mbox (Reini Urban)
    Re: backslash escaping not metacharacters in a char cla <lr@hpl.hp.com>
        Best way to hide source <root@web3.valley-internet.com>
    Re: common filehandle to read and write!! (Elaine -HFB- Ashton)
    Re: Converting HTML hex characters to characters mongoose@wpi.edu
    Re: Critique My Code <Tbone@pimpdaddy.com>
        Error Install GD-1.27 <yaqoota@emirates.net.ae>
    Re: Error Install GD-1.27 (Elaine -HFB- Ashton)
    Re: How can I delay "use"ing a module until the module  <uri@sysarch.com>
    Re: How can I delay "use"ing a module until the module  (Jerome O'Neil)
    Re: How can I delay "use"ing a module until the module  (Elaine -HFB- Ashton)
    Re: How can I delay "use"ing a module until the module  <DNess@Home.Com>
        how to get the error string for ($? >> 8) <vsp@us.net>
    Re: how to get the error string for ($? >> 8) (Greg Bacon)
        intrusive record separator at end of line: how can I ge <jd@mukh.asc.ox.ac.uk>
        more string handling <redmonkey@madasafish.comx>
    Re: more string handling (Greg Bacon)
    Re: more string handling <marshalc@americasm01.nt.com>
    Re: more string handling <lr@hpl.hp.com>
    Re: more string handling <sariq@texas.net>
    Re: Mysterious \n Character. Argh! <lr@hpl.hp.com>
    Re: Mysterious \n Character. Argh! (Craig Berry)
    Re: Need some help with an easy subroutine <gellyfish@gellyfish.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 24 Apr 2000 16:07:03 GMT
From: iforsyth@my-deja.com
Subject: Aborting a cycling batch program in Perl
Message-Id: <8e1rep$ouu$1@nnrp1.deja.com>

I have a dos batch program that I wrote in Perl.  Essentially, it's in
an infinite loop to check a directory and pick up files when they are
received.

What I would like to have is a way for a user to do a keyboard hit and
stop the program.   I checked the FAQ, and attempted to do a sysread
after putting the PC in raw mode; however, I couldn't seem to detect
the keyboard hit when I tested for it later in the program.  I suspect
this is due to the program cycling at such a fast rate, but I'm unsure.

What is the best way to detect an exit by a user?

Thanks,

Ian


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


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

Date: 24 Apr 2000 14:40:45 GMT
From: gbacon@ruby.itsc.uah.edu (Greg Bacon)
Subject: Re: Ambiguous Use -> {flock} and {"flock"}?
Message-Id: <8e1mdd$an3$1@info2.uah.edu>

In article <morbus-82D2F3.07040324042000@news.totalnetnh.net>,
	Morbus Iff <morbus@disobey.com> writes:
: 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};

Old versions of Perl gave this warning because $SETTINGS{flock} could
mean

    # the value associated with the value returned from flock()
    $SETTINGS{ flock() }

or

    # the value associated with the string "flock"
    $SETTINGS{"flock"}

It was decided that most Perl programmers mean the latter, so the
warning went away.

You can still run into related problems with code like

    sub foo {
        my @a = @{shift};

        ...;
    }

I usually write

    sub foo {
        my @a = @{ shift @_ };

        ...;
    }

to avoid the problem.

Hope this helps,
Greg
-- 
I went to a bookstore and asked the saleswoman, "Where's the self-help
section?"; She said if she told me, it would defeat the purpose.
    -- George Carlin


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

Date: Mon, 24 Apr 2000 13:24:27 GMT
From: rurban@x-ray.at (Reini Urban)
Subject: ANN: Outlook Express mbx  -> mbox
Message-Id: <39044ba8.14709741@judy>

mbx2mbox.pl

Author: 	Reini Urban <rurban@x-ray.at>
Created: 	<2000-04-22 11:26:16 rurban>
Time-stamp: 	<2000-04-24 14:21:56 rurban>
Description:
	Converts Outlook Express Ordner.mbx to unix mailbox format, 
          but with dos eof line conventions.
	It just strips the binary header markers and adds a Netscape
	acceptable "From" field at the start of the mail header.
	It optionally removes some unneeded header entries ("Received").
Usage: mbx2mbox [options] infile >outfile
Options:
	-noReceive 	remove all "Receive" entries
	-noX 		remove all "X-" header fields
URL:  ftp://xarch.tu-graz.ac.at/pub/autocad/urban/perl/
Copyright: 	2000 Reini Urban
	You may copy, redistribute it and/or modify it under the
	same terms as Perl itself.

--
Reini Urban
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html


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

Date: Mon, 24 Apr 2000 09:51:45 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: backslash escaping not metacharacters in a char class
Message-Id: <MPG.136e1b74fc220d1598a964@nntp.hpl.hp.com>

In article <390427D6.FAA639F7@recol.es> on Mon, 24 Apr 2000 12:54:15 
+0200, Javier Hernandez <fjhernandez@recol.es> says...
> 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 ?

What happened when you tried it?

(That is shorthand for this:  A simple experiment would give you the 
answer.  Even though I know the answer, I would do the same experiment 
as a matter of course before posting it.  Why should I do what you can 
do for yourself, especially when you might get good practice from doing 
it?)

> 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.

Your understanding could be verified by reading the Perl documentation 
about regular expressions.  Once again, you expect us to read the manual 
for you.

perldoc perlre

After you have read the documentation and tried some experiments, if any 
questions remain please ask them.

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


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

Date: Mon, 24 Apr 2000 17:26:04 GMT
From: System Administrator <root@web3.valley-internet.com>
Subject: Best way to hide source
Message-Id: <Ms%M4.15097$jZ3.199448@nuq-read.news.verio.net>


Ok first of all I don't want to get in any arguments about open source here:)  
If you feel the need to do so please make sure you read the entire message first.


Our company owns unix based credit card processing software that we have used internally
for a few years now.  We will be releasing the majority of it as open source (BSD style license)
within the month.

Our problem is that for some of the processing networks we are certified with we are under an NDA to
not disclose the message formats or the communications/data protocols.  Our long term goal is to
get the processors in question to let us disclose the source, but until we get that in writing there is no
way I am going to violate an NDA with a company like Firstdata:)

Ok so to the guts of my question.  I am trying to find the best way to structure the program since some of
it is open source and some is not.  Right now we have a single program written in perl that 
handles multiple processing networks within the same program.  I'd like to keep it like this instead of
having to have separate programs for the processing networks where we are under an NDA.  

I was thinking about having the main program be a binary that would contain within it the closed code, and 
have all the open source parts in their own modules outside of the binary.  The binary would contain code
that was open source, but in order to keep the closed source code closed, the open source part of the main
program would need to be compiled along with the closed portions, using the perl compiler of course.

The only other thought I had was to somehow encrypt the code and have the main program decrypt it and load
it every time it starts up.

Btw, I know that compiling it doesn't actually hide it if someone wants to get at it, it's the NDA I have
to account for though, and as long as the code is in binary format or encrypted I will be ok legally.  I
also do NOT want to upset someone like FDR, since they could basically make the software worthless if they
decide to pull the certification.

Also, if you don't mind please CC replies to chris@valley-internet.com if you don't mind.

Regards,

Chris Ochs


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

Date: 24 Apr 2000 16:47:33 GMT
From: elaine@chaos.wustl.edu (Elaine -HFB- Ashton)
Subject: Re: common filehandle to read and write!!
Message-Id: <slrn8g8ujr.n77.elaine@chaos.wustl.edu>

In article <8e0o2u$jn1$1@nnrp1.deja.com>, prakash_ojha@my-deja.com wrote:
>is there a common way to create filehandle for both read/append..

'perldoc perlopentut'

e.


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

Date: Mon, 24 Apr 2000 10:32:21 -0500
From: mongoose@wpi.edu
Subject: Re: Converting HTML hex characters to characters
Message-Id: <39046905.5FE6649@wpi.edu>

Tony Curtis wrote:
> 
> >> On Sat, 22 Apr 2000 17:46:03 -0500,
> >> mongoose@wpi.edu said:
> 
> > "Godzilla!" wrote:
> >>  mongoose@wpi.edu wrote: > > Ok one of my fields in an
> >> html forms > returns a string a users wrote, but if >
> >> the user puts in chars like ! or ? it > just returns
> >> the hex number in %3F or > something similiar. How do I
> >> convert these > hex strings into characters? I thought
> >> > this should work but this only seems to > not work
> >> with the \x character
> >>
> >> Your problems will vanish when you write your own read
> >> and parse. Be sure to address basic security issues
> >> once you rid your script of cgi.pm. You will find your
> >> script is more efficient and runs faster by not using
> >> cgi.pm at all.
> >>
> >> Again, address basic security issues when you write
> >> your own read and parse.
> 
> >   I looked at CGI.pm and did some basic stuff with
> > it. It seems kinda pointless in alot of respects. Im
> > just using template pages and am parsing through them
> > myself. Thats easy enough for me.
> 
> Well you know, CGI.pm has been a standard module for a
> number of years.  While you are of course free to use
> whatever method you want for handling CGI data, CGI.pm has
> proven its worth as an abstracted and encapsulated method
> of dealing with such data in a cross-platform way.  I'm
> sure lots of people can tell you that this is so.  I'm
> interested: *why* do you think it is "pointless in alot
> [sic] of respects"?  Surely parsing data read in from
> files in a program invoked through CGI is orthogonal to
> parsing data passed through the CGI interface?


   Well I just create html files I call templates, then I put special
characters designating where I want my perl script to put in generated
words. I don't have to type in lots of printfs for my html inside my
perl script. And I can change the webpage without having to edit the
perl script. Its a nice seperation. The perl script just takes care of
filling in the special words on the page and other file management on
the server. There really doesn't seem to be much to cgi other than
getting data from the web browser. Other than that its just alot of
parsing of data, database management...


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

Date: 24 Apr 2000 16:40:13 GMT
From: Intergalactic Denizen of Mystery <Tbone@pimpdaddy.com>
Subject: Re: Critique My Code
Message-Id: <8e1tdd$asv$1@news.enteract.com>

grichards@flashcom.net writes:
>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?

The code looks fine--much better than many "relative novices" that you
see. Does it run under use strict? Then it's all good. Style could be
more readable, or the relative unreadability could be an artifact of
posting. There are no efficiencies worth sweating over that will be
achieved merely by tinkering with the code. In other words, style and
efficiencies will come as you get more used to Perl; meanwhile, you
have written a good program.



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

Date: Mon, 24 Apr 2000 18:07:57 +0400
From: "Quaid Joher" <yaqoota@emirates.net.ae>
Subject: Error Install GD-1.27
Message-Id: <8e1kda$pak3@news.emirates.net.ae>

For the past two weeks I have been trying to properly install all the
graphics modules, libraries and programs and I have followed the following
procedure.  I am installing these in my home directory.

1. Installed zlib
2. Installed libpng
3. Installed GD-1.8.1
4. Installing GD-1.27 (GD.pm)

Following message I received on command "perl Makefile.PL
LIB=/usr/www/home/lib" (where home is my home);

  Checking if your kit is complete...
  Looks good
  Note (probably harmless): No library found for -lttf
  Note (probably harmless): No library found for -ljpeg
  Writing Makefile for GD

Following message I received on the next command "make"

cc -c -I/usr/www/home/include -I/usr/local/include/gd -I/usr/local/include -
O
   -DVERSION=\"1.27\"  -DXS_VERSION=\"1.27\" -DPIC -fpic -I/usr/local/lib/pe
rl5/
5.00502/i386-freebsd/CORE  GD.c
GD.xs: In function `XS_GD__Image_newFromXpm':
GD.xs:357: warning: assignment makes pointer from integer without a cast
Running Mkbootstrap for GD ()
chmod 644 GD.bs
LD_RUN_PATH="/usr/www/home/lib:/usr/lib" ld -o
lib/arch/auto/GD/GD.so  -Bshare
able  -L/usr/local/lib GD.o    -L/usr/www/home/lib -lgd -lpng -lz -lm
chmod 755 blib/arch/auto/GD/GD.so
cp GD.bs blib/arch/auto/GD/GD.bs
chmod 644 blib/arch/auto/GD/GD.bs
Manifying blib/man3/GD.3
(I have typed here 'home' where my site resides for security)

'make test' also failed....

Can some one guide me where I have made the mistake (if any) or what step
that I may have missed out.  My thanks to Tom Phoenix to guide me in the
early stages.

QUAID





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

Date: 24 Apr 2000 15:46:28 GMT
From: elaine@chaos.wustl.edu (Elaine -HFB- Ashton)
Subject: Re: Error Install GD-1.27
Message-Id: <slrn8g8r1a.n77.elaine@chaos.wustl.edu>

In article <8e1kda$pak3@news.emirates.net.ae>, Quaid Joher wrote:
>For the past two weeks I have been trying to properly install all the
>graphics modules, libraries and programs and I have followed the following
>procedure.  I am installing these in my home directory.
>
>1. Installed zlib
>2. Installed libpng
>3. Installed GD-1.8.1

From the README which should tell you where you might find the jpeg library
as well...If you have done all of this and are still having problems, I have
patch I used for my solaris system, but I suspect that you haven't followed 
the directions fully. 

e.

INSTALLATION:

Read these instructions all the way through before you start!

1.  Make sure you have downloaded and installed the following packages:

        a. Perl 5.004 or higher:
                http://www.perl.com/

        b. The gd graphics library, version 1.6.3 or higher:
                http://www.boutell.com/gd/

        c. The PNG graphics library:
                http://www.cdrom.com/pub/png/

        d. The zlib compression library:
                http://www.cdrom.com/pub/infozip/zlib/

        e. The FreeType font rendering library for TrueType fonts
           (optional):
                http://www.freetype.org/

        f. The JPEG library, version 6b or later (optional):
                ftp://ftp.uu.net/graphics/jpeg/

        g. The XPM library, a standard part of modern X Windows 
           distributions (optional).  If you don't have a modern
           version of X, don't try to get XPM working.

2. OPTIONAL -- patch the libgd distribution

Some users have had trouble getting GD to link correctly.  Part of the
problem is that Perl's Makefile.PL system prefers dynamically-linked
shared libraries, but libgd builds a static library file by default.
The file C<patch_gd.sh>, included with this distribution, will patch
libgd version 1.8.1 to make it possible to compile it as a shared
library.

This file is a shell script.  To use it, copy it into the top level of
a B<virgin> copy of the gd-1.8.1 directory.  Then run it like this:

  % sh patch_gd.sh

This will patch the libgd distribution so that it works with the GNU
autoconfiguration system.  Read the README and INSTALL files that were
created by the script and follow the directions.

It is possible that this patch will work with later version of libgd,
but this is not guaranteed by any means."


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

Date: Mon, 24 Apr 2000 15:52:04 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: How can I delay "use"ing a module until the module is needed?
Message-Id: <x7purf4huk.fsf@home.sysarch.com>

>>>>> "G" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:

hey purlmoron,

you promised to go away for a log time. so you lie about that as well.


  G> $test = "fubar";

  G> if ($test eq "not_fubar")
  G>  {
  G>   use LWP::Simple;

ok, dipshit, that is NOT executing a module, it is loading it. you don't
knwo the difference which is blatantly obvious. go back to purl4 and
stop trying to play with the big children. wrtie your own http code
(hmm, why are you even trying to use LWP given you distaste for modules?).

  G>   $test_lwp = get ("http://www.dalmatia.net/lupic/asimov.htm");
  G>   print "LWP has been executed. Results: $test_lwp \n\n";

that code is not executed idiot! the module IS loaded before the if
condition is even run.
  G>  }



  G> ## Redundancy Test:

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

moron, LWP is not executed it was LOADED

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


you have no grasp of these words as they are used and they all have very
clearly defined meanings in computer science and even english:

executed
loaded
evaluated
module
compile
runtime

  G>    * Enjoys a good laugh *

stop using modules as you have no concept of how they work or anything
to do with compile time issue in perl.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Mon, 24 Apr 2000 16:59:55 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: How can I delay "use"ing a module until the module is needed?
Message-Id: <f4%M4.387$r21.17481@news.uswest.net>


> Technical journal writers should be subject to
> a prerequisite of a degree in English before
> being allowed to contribute technical articles
> for publication.

Now that we know who you realy are, I have had the time to
examine some of the work in your actual field of "expertise."

The fact that you don't know squat about Perl, computers, CGI, 
or anything even remotely technical can be forgiven.

The fact that a professed PhD in english writes such purile, 
juvenile and outright *bad* prose is not.

You're not just a troll, you're a sad troll.


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

Date: 24 Apr 2000 17:07:25 GMT
From: elaine@chaos.wustl.edu (Elaine -HFB- Ashton)
Subject: Re: How can I delay "use"ing a module until the module is needed?
Message-Id: <slrn8g8vp3.n77.elaine@chaos.wustl.edu>

In article <x7purf4huk.fsf@home.sysarch.com>, Uri Guttman wrote:
>>>>>> "G" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:
>
>hey purlmoron,
>
>you promised to go away for a log time. so you lie about that as well.

Uri behave :) Besides, you might need the hair replacement lotion stuff 
if you keep up at this rate. 

No need to take on the character of mothra. Lighten up, you can correct
with a sense of humour. Afterall, it has taken on the patina of almost
legendary proportion. Making it personal and getting nasty is just the
sort of reaction he/she/it wants. 

Domo arigato...

 . o 0 ( Oh bugger, now I'm going to have that stupid 'turning japanese'
	song going round in my head for the rest of the afternoon )

e.


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

Date: Mon, 24 Apr 2000 17:40:49 GMT
From: David Ness <DNess@Home.Com>
Subject: Re: How can I delay "use"ing a module until the module is needed?
Message-Id: <39048729.85EA0E97@Home.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.

Well, given some people I know who _have_ degrees in English, I
doubt if much would be gained by making a them prerequisite to anything.
But that's another matter...

> ... for discussion is a must and well abided concept
> amongst trained scientists. In this case, terms ...

`well abided'?

> These claims a module is executed regardless, are simply
> not accurate. 

`claims a module is executed regardless'?

> 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.
> 

As, it seems to me, is the sentence itself?

Your English isn't _bad_. However, it is bad enough that you shouldn't
pick on other people's English for your living.

Stick to your day job.


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

Date: Mon, 24 Apr 2000 14:40:26 GMT
From: li <vsp@us.net>
Subject: how to get the error string for ($? >> 8)
Message-Id: <8e1mcn$j7a$1@nnrp1.deja.com>

Hi,

Is there a way to get the error string for errors returned by 'system'
command?

Graham Barr's Errno.pm gives the system E* status code, but how do one
gets the string?   (By getting correspondent comment line in the
errno.h?  :-)


Thanks for helping,

vlad


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


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

Date: 24 Apr 2000 15:59:50 GMT
From: gbacon@ruby.itsc.uah.edu (Greg Bacon)
Subject: Re: how to get the error string for ($? >> 8)
Message-Id: <8e1r1m$bjk$2@info2.uah.edu>

In article <8e1mcn$j7a$1@nnrp1.deja.com>,
	li <vsp@us.net> writes:

: Is there a way to get the error string for errors returned by 'system'
: command?

Values of $? correspond to exit status values.  The only way to convert
those to strings is by looking them up in the appropriate manpage.

Greg
-- 
As a general rule, don't solve puzzles that open portals to Hell. 
    -- Ralph Mason


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

Date: Mon, 24 Apr 2000 18:23:32 +0100
From: jd <jd@mukh.asc.ox.ac.uk>
Subject: intrusive record separator at end of line: how can I get rid of it?
Message-Id: <39048314.F81DD3D9@mukh.asc.ox.ac.uk>


--------------AFFA145219B32C84C136D947
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I'm writing a small (novice's) script as a way to learn some more
perl .    I've got a file with errors, and I want to read the file,
find the errors, correct them, and write the corrected version
to a tmp file.

I read the file in, line by line, and chop and split it

    @Rec = split(/\t/, $_, 9999);

then I do all the checking and correcting, and write the
record out:

    print TMP join("\t", @Rec), "\n";

This seems to put _both_ the field and the record separator
at the end of each record:   on altered and on unchanged lines,
each time I use the script.   So each record (about 5000 of them)
gets a new tab at the end  each time I  write to file.    It doesn't
make any difference particuarly, but I don't really want to accumulate
thousands of useless tabs;   and in any case I ought to learn how
to write code that does precisely what I want.

If anyone has the time to point me to the correct way to do it,
I'd be very grateful.  (I've got Wall & Schwartz, and Christiansen
& Torkington, but they don't signal this mistake clearly enough
for me to find it).

jd

--
John Davis

All Souls College
Oxford
+44 (0) 1865 279300
jd@mukh.asc.ox.ac.uk



--------------AFFA145219B32C84C136D947
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
I'm writing a small (novice's) script as a way to learn some more
<BR>perl .&nbsp;&nbsp;&nbsp; I've got a file with errors, and I want to
read the file,
<BR>find the errors, correct them, and write the corrected version
<BR>to a tmp file.

<P>I read the file in, line by line, and chop and split it

<P>&nbsp;&nbsp;&nbsp; @Rec = split(/\t/, $_, 9999);

<P>then I do all the checking and correcting, and write the
<BR>record out:

<P>&nbsp;&nbsp;&nbsp; print TMP join("\t", @Rec), "\n";

<P>This seems to put _both_ the field and the record separator
<BR>at the end of each record:&nbsp;&nbsp; on altered and on unchanged
lines,
<BR>each time I use the script.&nbsp;&nbsp; So each record (about 5000
of them)
<BR>gets a new tab at the end&nbsp; each time I&nbsp; write to file.&nbsp;&nbsp;&nbsp;
It doesn't
<BR>make any difference particuarly, but I don't really want to accumulate
<BR>thousands of useless tabs;&nbsp;&nbsp; and in any case I ought to learn
how
<BR>to write code that does precisely what I want.

<P>If anyone has the time to point me to the correct way to do it,
<BR>I'd be very grateful.&nbsp; (I've got Wall &amp; Schwartz, and Christiansen
<BR>&amp;&nbsp;Torkington, but they don't signal this mistake clearly enough
<BR>for me to find it).

<P>jd
<PRE>--&nbsp;
John Davis



All Souls College
Oxford
+44 (0) 1865 279300
jd@mukh.asc.ox.ac.uk</PRE>
&nbsp;</HTML>

--------------AFFA145219B32C84C136D947--



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

Date: Mon, 24 Apr 2000 16:57:50 GMT
From: "red" <redmonkey@madasafish.comx>
Subject: more string handling
Message-Id: <i2%M4.8464$VR6.865068@news3.cableinet.net>

okay, this might be a little hard to explain:
i want to limit a string to say 80 characters,
if its more, i want it cut, and add ... to the end.
if its not that long, dont add 3 dots.

okay, not so difficult. thx.
--

Graham "red" Reeves

uk's Q3 news - - www.quadmonkey.co.uk
newsDuck news engine - - www.fravia.com/newsduck/
beOS icon and design - - www.fravia.com







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

Date: 24 Apr 2000 17:03:48 GMT
From: gbacon@ruby.itsc.uah.edu (Greg Bacon)
Subject: Re: more string handling
Message-Id: <8e1upk$cc2$2@info2.uah.edu>

In article <i2%M4.8464$VR6.865068@news3.cableinet.net>,
	"red" <redmonkey@madasafish.comx> writes:

: okay, this might be a little hard to explain:
: i want to limit a string to say 80 characters,
: if its more, i want it cut, and add ... to the end.
: if its not that long, dont add 3 dots.

$str =~ s/^(.{77}).{4,}+/$1.../s;

Greg
-- 
Comfort rides shotgun with the temporary.
    -- Daniel Weinshenker


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

Date: Mon, 24 Apr 2000 12:21:38 -0500
From: Marshall Culpepper <marshalc@americasm01.nt.com>
Subject: Re: more string handling
Message-Id: <390482A2.7FF6DFDE@americasm01.nt.com>

red wrote:
> 
> okay, this might be a little hard to explain:
> i want to limit a string to say 80 characters,
> if its more, i want it cut, and add ... to the end.
> if its not that long, dont add 3 dots.

Well, if you want to do it in perl:

% cat test
#!/usr/bin/perl -w
use strict;
my $string = 'Aa' x 44;
substr($string,80) = "..." unless length $string <= 80;
print $string;

% perl test
AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa...




> 
> okay, not so difficult. thx.
			 ^^^^^
Explain this 'thx' , I'm not sure what you mean (And if it has anything
to do with thanking me, you didn't achieve it very well.)

~Marshall
-- 
perl -e 'print pack
"c*"=>(((4<<4)|10),((7<<4)|5),((7<<4)|3),((7<<4)|4),(2<<4),
((4<<4)|1),((6<<4)|14),((6<<4)|15),((7<<4)|4),((6<<4)|8),((6<<4)|5),
((7<<4)|2),(2<<4),(5<<4),((6<<4)|5),((7<<4)|2),((6<<4)|12),(2<<4),
((4<<4)|8),((6<<4)|1),((6<<4)|3),((6<<4)|11),((6<<4)|5),((7<<4)|2))'


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

Date: Mon, 24 Apr 2000 10:26:35 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: more string handling
Message-Id: <MPG.136e23a491a3c9be98a967@nntp.hpl.hp.com>

In article <8e1upk$cc2$2@info2.uah.edu> on 24 Apr 2000 17:03:48 GMT, 
Greg Bacon <gbacon@ruby.itsc.uah.edu> says...
> In article <i2%M4.8464$VR6.865068@news3.cableinet.net>,
> 	"red" <redmonkey@madasafish.comx> writes:
> : i want to limit a string to say 80 characters,
> : if its more, i want it cut, and add ... to the end.
> : if its not that long, dont add 3 dots.
> 
> $str =~ s/^(.{77}).{4,}+/$1.../s;
                         ^
Nice, but the '+' quantifier is redundant.

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


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

Date: Mon, 24 Apr 2000 12:58:53 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: more string handling
Message-Id: <39048B5D.787D0614@texas.net>

Marshall Culpepper wrote:
> 
> red wrote:
> >
> > okay, this might be a little hard to explain:
> > i want to limit a string to say 80 characters,
> > if its more, i want it cut, and add ... to the end.
> > if its not that long, dont add 3 dots.
> 
> Well, if you want to do it in perl:
> 
> % cat test
> #!/usr/bin/perl -w
> use strict;
> my $string = 'Aa' x 44;
> substr($string,80) = "..." unless length $string <= 80;
> print $string;

Or, perhaps:

#!/usr/bin/perl -w

use strict;

my $string = '0123456789' x 9;
my $rest = substr($string,80,length $string,'...') 
     if length $string > 80;
print "$string\n$rest\n";

__END__

in case you need the rest.

- Tom


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

Date: Mon, 24 Apr 2000 09:58:22 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Mysterious \n Character. Argh!
Message-Id: <MPG.136e1d0d8209eebc98a965@nntp.hpl.hp.com>

In article <morbus-BAB220.08561824042000@news.totalnetnh.net> on Mon, 24 
Apr 2000 08:56:18 -0400, Morbus Iff <morbus@disobey.com> says...

 ...

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

'chop' is a poor choice, because it will remove the last character in 
its argument string, no matter what the character is.

'chomp' is a better choice, because it will remove the contents of $/ 
("\n" by default) if that is the last character in the string.  So there 
is no harm in using chomp() as 'a matter of principle', if you wish.

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


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

Date: Mon, 24 Apr 2000 17:23:52 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Mysterious \n Character. Argh!
Message-Id: <sg90p8o7cdo133@corp.supernews.com>

Morbus Iff (morbus@disobey.com) wrote:
: 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}");

Not checking the result of open is masochism.  Also, there's no need to
put the second argument in double-quotes; in fact, it just creates more
work for perl doing a meaningless interpolation.

:   @line = <AREASCACHE>; close(AREASCACHE);

Just a style tip:  I like using plurals or aggregation terms to name my
arrays.  '@lines' seems more intuitive here, for example.

:   foreach $line (@line) {

Many of your problems below arise because you don't do

      chomp $line;

right here.  This would remove the trailing newling (\n) from $line before
further processing.

:   ($areas_file, $modtime, $room, $north, $south, $east, $west, 
:    $northeast, $northwest, $southeast, $southwest, $up, $down) = 
:    split(/\|\%\|/, $line);

First, that multiply-escaped regex could more consisely be written as
/\Q|%|/.

Second, I'd choose a diffent data structure for representing your records.
I would define the field names expected up above, outside the loop, using

  my @field_names = qw(areas_file modtime room
                       north south east west
                       northeast northwest southeast southwest
                       up down);

then do

  my %record;
  @record{@field_names} = split /\Q|%|/, $line;

to collect the values.

:   $line =~ s/^\n//isg;

As you mention below, this line is pointless, but it's especially
pointless given that you do it *after* splitting out the fields!  Also,
note that none of the qualifiers you've applied are meaningful in this
context.  \n has no case, it's not a . metacharacter, and there can be
only one (with apologies to The Highlander) given how you're reading the
file.  Avoid throwing random cruft at code to make it work.  It almost
never does.

:   if ($CHECKEDAREASCACHE{$areas_file}) { next; }       

Minor style note, purely a matter of taste:  This can also be written as

  next if $CHECKEDAREASCACHE{$areas_file};

Or, if you adopt my data structure above,

  next if $CHECKEDAREASCACHE{$record{areas_file}};

That should be enough to get you started in the right direction.  Good
luck!

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: 23 Apr 2000 20:17:38 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Need some help with an easy subroutine
Message-Id: <8dvi8i$u8g$1@orpheus.gellyfish.com>

On Sun, 23 Apr 2000 15:22:37 GMT Kragen Sitaker wrote:
>                       think like an American

I'd rather not if you dont mind. 

/J\
-- 
No! No no no no no no! Well, yes.
-- 
fortune oscar homer


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

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


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