[7756] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1381 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 27 21:07:58 1997

Date: Thu, 27 Nov 97 18:00:25 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 27 Nov 1997     Volume: 8 Number: 1381

Today's topics:
     $x.xx in PERL <perrella@dclsn23.ews.uiuc.edu>
     A difficult problem <hemant@synopsys.com>
     Re: A difficult problem <hemant@synopsys.com>
     Re: Can I do $! = 'string' ? <rjk@coos.dartmouth.edu>
     Re: deleting a line in an ascii file (Jan Pazdziora)
     Re: For the pro's ? repost: Leaving HTML tags alone <ajh@rtk.com>
     Re: Getting file timestamp from array (Jim Allenspach)
     Re: getting output from system <qdtcall@esb.ericsson.se>
     Re: how to do dos command inside perl (in nt) <koos_pol@bigfoot.com>
     Re: interpreted languages <donal@ugglan.demon.co.uk>
     Re: interpreted languages (Steve Austin)
     Leaving HTML-Tags alone=solved. (Patrick)
     Re: Newbie question.   Do you recommend moving from C? <nikki@trmphrst.demon.co.uk>
     Re: Newbie question.   Do you recommend moving from C? <myles@kcbbs.gen.nz>
     Re: PERL Hourly Rates <mageos@hotmail.com>
     Re: PERL Hourly Rates <mageos@hotmail.com>
     Please help with form script (Wolfgang Viechtbauer)
     Re: reading a remote site's html? (brian d foy)
     Re: Safe use of flock() -- was Re: giving up on flock (Keith Willis)
     Re: Silly diamond operator (<>) problem? <mcdermidg@acm.org>
     Re: Sorting an 'almost but not really' complicated data <rjk@coos.dartmouth.edu>
     Re: system vs. backtics.  What difference? <NOstitt@persoft.comSPAM>
     Re: trouble with libwww & friends in nonstandard libdir <david@hq.tip.nl>
     Re: truncating a string <rjk@coos.dartmouth.edu>
     Re: Variable Pattern Options <robert.friberg@your_clothes.eductus-vast.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 27 Nov 1997 00:42:57 -0600
From: perrella andrew c <perrella@dclsn23.ews.uiuc.edu>
Subject: $x.xx in PERL
Message-Id: <Pine.GSO.3.96.971127003832.1479A-100000@dclsn23.ews.uiuc.edu>


Hello, 

	I have writte a script that is used for catalog orders.  It sums
the items taken, figures out tax and shipping and then adds them all up.
the problem is that I can't seem to truncate the total after 2 decimal
places.

	It is not uncommon for tax to be 2.3456785 or something like that.
I would like to be able to make that number 2.35 or if nothing else just
cut it off at 2 places without rounding.

	I have tried a few methods but nothing seems to work well.


Thanks for any help

Andrew Perrella
perrella@uiuc.edu




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

Date: Thu, 27 Nov 1997 18:16:06 +0530
From: Hemant Mallapur <hemant@synopsys.com>
Subject: A difficult problem
Message-Id: <347D6B8E.41C67EA6@synopsys.com>

Hi,

I'm trying to build a complex (for me) data structure and
am not able to make it work correctly. Could the Perl gurus
help me? I would be grateful for your help - this problem
has really bugged me. Please send a cc to me @
 hemant@synopsys.com.

The idea is to build a table that is a hash whose "key" is
from an array @padname. The "value" stored is a reference to
another hash whose "key" is from @names. The "value" stored in this
array is a reference to a list array (containing number values)
@dataref0.

To show it pictorially this is the idea :
Table
|-->  pad1---> this----> (0.1, 0.2 ...)
|        |---> that----> (1.1, 1.2 ...)
|        |---> him-----> (2.1, 2.2 ...)
|        |---> her ----> (3.1, 3.2 ...)
|
|-->  pad2----> this .... (4.1, 4.2, ...)
|        |---->....
 .... 
 
For this I've written the following code to build a table
and print out all values. I increment values in the numerical
list @dataref0 so that "this" of "pad2" should be (4.1, 4.2 etc)
where they are (0.1, 0.2 ...etc) for "pad1". However this
does not happen. And table{pad2}{this} is being written with
identical data as table{pad1}{this}.
--------------- Script begins -----------

@dataref0 = ( 0.1, 0.2, 0.3, 0.4 );
@names = ( this, that, him, her );
@padname = ( pad1, pad2, pad3, pad4 );
 
print "Building the table\n";
 
foreach $padname (@padname) {
 
   print "padname : $padname\n";
   foreach $name (@names) {
     print "name : $name\n";
     foreach $i (0 .. $#dataref0) {
        print "Before : dataref0 elem # $i is $dataref0[$i]\n"
     }
 
     push @{ $entry{$name} } , [ @dataref0 ];
 
     print "\n\n";
   }
 
   push @{ $table{$padname} } , [ %entry ];
 
 
   print "Trying to print the table\n";
 
   foreach $entryname (keys %table) {
 
     print  "\n\nkey : $entryname\n";
 
     %read = ();
 
     %read = @{ $table{$entryname}[0] };
 
     foreach $key ( keys  %read) {
       print " entry key : $key\n";
       @arr = @{ $read{$key}[0] };
       print "    value : ";
       foreach $elem ( @arr) {
         print "$elem, ";
       }
       print "\n";
     }
   }
}
 
------------------- End of script ----------------

Thank you,

Hemant
-- 
-----------------------------------------------------------------------
 Hemant Mallapur                       Email : hemant@synopsys.com
 Synopsys (India) Pvt Ltd.             Phone : 91-80-221-5470/5483
 85, Richmond Road, Bangalore,         Fax   : 91-80-221-0575
 India - 560025
-----------------------------------------------------------------------


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

Date: Thu, 27 Nov 1997 18:39:47 +0530
From: Hemant Mallapur <hemant@synopsys.com>
Subject: Re: A difficult problem
Message-Id: <347D711B.167EB0E7@synopsys.com>

Hi,

Oops! In my question posting I missed putting these 4
lines in my script below....

Hemant Mallapur wrote:
> 
> Hi,
> 
> I'm trying to build a complex (for me) data structure and ....

 .... the script
>      push @{ $entry{$name} } , [ @dataref0 ];

---- Add these 4 lines -----

     foreach $i (0 .. $#dataref0) {
         $dataref0[$i] += 1;
         #print "After : dataref0 elem # $i is $dataref0[$i]\n"
     }

----- End of modification ----
> 
>      print "\n\n";
>    }
> 
>    push @{ $table{$padname} } , [ %entry ];
> 
> 
>    print "Trying to print the table\n";
> 
----

Hemant

-- 
-----------------------------------------------------------------------
 Hemant Mallapur                       Email : hemant@synopsys.com
 Synopsys (India) Pvt Ltd.             Phone : 91-80-221-5470/5483
 85, Richmond Road, Bangalore,         Fax   : 91-80-221-0575
 India - 560025
-----------------------------------------------------------------------


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

Date: Thu, 27 Nov 1997 01:31:41 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Can I do $! = 'string' ?
Message-Id: <347D13CC.6CF9@coos.dartmouth.edu>

Faust Gertz wrote:
> 
> You can probably collect [the error messages] by running the following untested
> script.
> 
> #!/usr/local/bin/perl
> 
> $! = $_ = 1;
> while ("$_" ne "$!") {
> print "$_ = $!\n";
> $!++;
> $_++;
> }

No offense, but that's rather silly.

The magical conversion of $! to an error message in string context
*only* works for $!.  Even if you had assigned from $! to $_, you're
only assigning the error number and not the magical conversion feature.
Your code will go into an infinite loop, because "$_", an integer, will
never equal "$!", an error message.  (If the magical conversion did
work, your code would never enter the while loop, because "$_" would be
equal to "$!" right away.)

The following code has been tested:

for ($!=1; not $! =~ /^unknown error$/i; ++$!) {
  print $!+0, " = $!\n";
}

Chipmunk


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

Date: Thu, 27 Nov 1997 12:32:59 GMT
From: adelton@fi.muni.cz (Jan Pazdziora)
Subject: Re: deleting a line in an ascii file
Message-Id: <EKB1J0.4Cn@news.muni.cz>

Asmat Ullah <asmat@cad.strath.ac.uk> wrote:

> I need to know how to delete a line from this flat file.
> 
> example line:
> 
> Joe:Bloggs:MR:332442:Joe@someplace.com:Room1111

perl -i -pe 'print unless
	$_ eq "Joe:Bloggs:MR:332442:Joe@someplace.com:Room1111\n";'
								filename

Untested. Also check the FAQ.

Hope this helps,



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

Date: 27 Nov 1997 12:46:13 GMT
From: "Aaron Harsh" <ajh@rtk.com>
Subject: Re: For the pro's ? repost: Leaving HTML tags alone
Message-Id: <880634772.460729@ridge.spiritone.com>

Venice @ euronet.nl (Patrick) wrote in message <65hi7m$lab$1@news.NL.net>...
>I want to replace the text in a HTML document...
>but i don't want to change the HTML code...
[snip]
>Or with other words: Replacements without touching things between <>
>How can i solve this in a short/fast piece of code ?

This seems to work:

$text = "$`$1$2Hypertext Transfer Protocol$'"
    while $text =~ /(^|>)([^<]*)http/;

Seems to be short, I don't know about fast.




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

Date: 27 Nov 1997 07:52:51 -0600
From: jima@REMOVE.ME.mcs.com (Jim Allenspach)
Subject: Re: Getting file timestamp from array
Message-Id: <65jtvj$ojo$1@Mars.mcs.net>

>opendir (CARDDIR, $dir);
>@filearray = readdir(CARDDIR);
>foreach $file (@filearray) {
>$time = (stat($file))[9];
>$ltime = localtime($time);
>}

>Anyone got a clue ?

	Yes; if you check your Blue Camel book, you'll find a caveat at the
end of the readdir() definition that says the result of readdir() needs to
have the directory re-attached to it. So, in your example, the stat() line
inside the loop might look like

	$time = (stat("$dir/$file"))[9];

Hope this helps...

jma


					No .sig today, as it's a holiday.


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

Date: 27 Nov 1997 09:31:06 +0100
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: getting output from system
Message-Id: <is90uaeo1h.fsf@godzilla.kiere.ericsson.se>

"Michael R. Harper" <mikihasa@worldnet.att.net> writes:

> I would like to capture (save as a variable) the output (STDOUT) from a
> program that I execute (using the system command) during a Perl script.
> Can anyone give this Perl newbie some help?

Sure: read the documentation!

>From the entry for system() in the perlfunc manpage:

This is NOT what you want to use to capture the output from a command,
for that you should use merely backticks or qx//, as described in the
section on `STRING` in the perlop manpage.

-- 
		    Calle Dybedahl, UNIX Sysadmin
       qdtcall@esavionics.se  http://www.lysator.liu.se/~calle/


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

Date: Thu, 27 Nov 1997 09:43:13 +0100
From: Koos Pol <koos_pol@bigfoot.com>
Subject: Re: how to do dos command inside perl (in nt)
Message-Id: <347D32A1.5099@bigfoot.com>

Rey Andrada wrote:
> 
> Hi All,
> 
> how to do dos command inside perl (in nt)
> 

system 'dir';
system $batchfile;

-- 
Koos Pol
----------------------------------------------------------------------
S.C. Pol                                           tel: +31 20 3116122
PC Systems Administrator                   email: Koos_Pol@bigfoot.com
Compuware Europe                 PGP public key available upon request

      A little inaccuracy sometimes saves tons of explanation.
                        -- H. H. Munroe


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

Date: Wed, 26 Nov 1997 23:30:43 +0000
From: "Donal K. Fellows" <donal@ugglan.demon.co.uk>
Subject: Re: interpreted languages
Message-Id: <p1yulCAjELf0Ewnj@ugglan.demon.co.uk>

In article <65ek9h$1al$1@srv38s4u.cas.org>, lvirden@cas.org writes
>Curious that the interpreter just doesn't 'run SF' itself when ever the
>code is run - or does it modify the original source?

The problem is probably that SF makes some assumptions that are not true
in general of Scheme; just true in those 99.9% of cases that occur in
real life :^)  The key assumption is probably[*] that none of the
built-in operators/functions are redefined.  As long as this is true,
you can make things a lot faster by inlining the code for those ops, but
it is a change from the defined semantics of the language.

Curiously, in Tcl you actually have similar problems, but redefinition
of commands/procedures is far more common, so the people at Sun who
developed the compiler system had to resolve this issue (at some
cost to performance/memory usage too)

Donal.
[* Speaking with a knowledge of functional language systems and
   compilers.  Don't ask me if this is really the case.
-- 
Donal K. Fellows


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

Date: 26 Nov 1997 14:22:34 GMT
From: steve_austin@bigfoot.com (Steve Austin)
Subject: Re: interpreted languages
Message-Id: <slrn67ofrn.8sm.steve_austin@boycat.kickham.com>

On Tue, 25 Nov 1997 21:39:12 -0500, Jrm <emergent@cape.com> wrote:
>Donal Fellows asks:
>>Is SF supplied with MIT Scheme, or at least mentioned in the
>>documentation that comes with it?
>
>The SF program comes with MIT Scheme.

Just to clarify a little, it's not a standalone program: it's invoked as a
procedure within MIT Scheme as

	(sf FILENAME [DESTINATION])

It's described in the User's Guide under "Compiling Programs".
   
--------------------------------------------------------------------------
Steve Austin                                   Powered by Linux since 1995 
steve_austin@bigfoot.com                                     RedHat 2.0.18
               Fight Spam - Join CAUCE - http://www.cauce.org


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

Date: Thu, 27 Nov 1997 21:32:09 GMT
From: Venice @ euronet.nl (Patrick)
Subject: Leaving HTML-Tags alone=solved.
Message-Id: <65jpbu$565$1@news.NL.net>

Problem was to replace text outside HTML tags, so the HTML will not be
replaced accidentally.

Here the answer,

Thought i post it for they who are interested and they who replied to
me.

s/$search(?=(?:[^>])*(?:[<\n]))/$replace/ig;

If i forgot something.. you tell me.
This does not exclude Multi-line HTML tags...


Thanx for the tips you perl people !!

Patrick



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

Date: Thu, 27 Nov 1997 13:03:30 GMT
From: Nikki Locke <nikki@trmphrst.demon.co.uk>
Subject: Re: Newbie question.   Do you recommend moving from C?
Message-Id: <VA.000003b4.00ad3dfb@trmphrst.demon.co.uk>

In article <347C5CAC.6C29@mb.sympatico.ca>, Programming wrote:
> I have been experiencing 
> "the joy of C" the past few months. 
>  
> My big complaint of using c is
> that it has no string type. 
> This also involves memory, pointers,
> syntax, etc.  Massive learning curve. 
>  
> So, what would be 2 statements in say Visual Basic, 

[2 lines of Basic omitted]

> becomes many statements in c.

[4 lines of C, roughly equivalent to 
char *ls_temp = strdup("testing");
omitted]

> Does anyone have any experience moving from
> C to either of these two languages on AIX.
> What have your experiences been?  Would
> you recommend it, or just stick with C?
>  
> What I am concerned with is:
> - software/code that is reliable!

C programs tend to have obscure bugs which cause unexpected program 
crashes, usually caused by bad pointers. Unless the programmers are 
very good, or just very careful.

Java programs avoid bad pointer bugs altogether, and whole classes of 
other bugs (such as memory leaks). However, the language is immature, 
it's still evolving quite rapidly, and the libraries have plenty of 
bugs.

> - relatively short learning curves. 

C is not too difficult to learn, once you understand pointers. It 
then takes quite a long time to get good at it. However, if you want 
object orientation (and I think you probably should), you get 
involved with C++, which is quite a lot more difficult. Of course, if 
you want graphical applications, you also have to learn the API of 
your chosen GUI, which can be quite involved. And you have to choose 
a specific GUI or GUI library, or get involved in porting.

Java is object oriented, has a standard GUI API which isn't that 
complicated, and is pretty easy to learn - lots easier than C++, 
anyway. Right now, however, you only get access to quite a small 
subset of your native GUI, and you may find you can't do some things 
you would like to do (e.g. iconifying and restoring your app, complex 
printing, drag and drop to other apps).

> - simple business that is simple, not complicated 
> (ie. assign the string to the variable)

Java probably better than C in this respect, due to the String 
object, and garbage collection.

> - what works one year, will work 10 years from now
> (no frequent upgrades and code changes required)

Java probably out, then. Probably graphical user interface out too?

> - compilers that give meaningful error messages

Are there any compilers in any language that do? :-)

> - code interfaces easily with Oracle, and can do
> embedded SQL.

I don't think you can do embedded SQL in Java, in the same sense that 
you do in C. However, you can do SQL using jdbc. I haven't tried it 
yet, but I would expect it to be a bit clunky right now.

> I am looking at this from a manager's standpoint.
> Can we use the language as a reliable tool that 
> will do what we expect a language to do for us?  
> That is, in creating and writing full blown 
> business applications.

For business applications I would strongly recommend _AGAINST_ C or 
C++. I would reluctantly recommend against Java right now, as I 
don't think it is sufficiently finished. COBOL, anyone?

-- 
Nikki Locke, Trumphurst Ltd.      PC & Unix consultancy & programming
nikki@trmphrst.demon.co.uk            http://www.trmphrst.demon.co.uk



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

Date: 27 Nov 1997 08:37:07 GMT
From: "Myles Penlington" <myles@kcbbs.gen.nz>
Subject: Re: Newbie question.   Do you recommend moving from C?
Message-Id: <01bcfb0f$13543c20$45660eca@myles-jo>


You could always try Borland's Delphi (Object Pascal) or Borland JBuilder
if you are looking for Java stuff.

Some of the Java stuff I like some I hate.. Still has too much code either
way, but Java has definite advantages and disadvantages over C/C++. Give
Java another Year or two to mature and get some real good GUI development
tools and it could be another story.

At the moment I favor Delphi for good Win95/NT stuff but in a years time it
could/will be Java for serious commercial development - Who knows the
future and how fast Java will develop.


Myles



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

Date: Wed, 26 Nov 1997 21:23:22 -0800
From: "Matt Osborne" <mageos@hotmail.com>
Subject: Re: PERL Hourly Rates
Message-Id: <65j06o$d48@dfw-ixnews12.ix.netcom.com>

I'm sure that this set of news is long dead, but I just subscribed.
before you hire a CGI programmer that claims to know perl, check to see what
other languages they know.  I am a senior in high school  and can program in
a variety of languages, not necessarily because I am smart but more because
once you learn the fundamentals of programming, such as objects or methods,
functions and procedures, arrays and types, you can "pick up" other
languages easier.  Before you hire someone, check there programming history.
Even though they will be programming CGI, the same kind of logic applies
that applies to regular programming.
Toutatis wrote in message ...
>comdog@computerdog.com (brian d foy) wrote:
>
>> In article <3475A7B3.819F9C2E@bridge.bellsouth.com>, Matthew Bonvicin
><Matthew.Bonvicin@bridge.bellsouth.com> wrote:
>>
>> >Could someone please provide for me an approximate hourly rate for
>> >advanced PERL CGI scripting.  I may have the need shortly to outsource
>> >some development but am unsure what to expect.
>>
>> CGI scripting is trivial.  if the programmer has other skills, then
>> you may have to pay more than minimum wage.
>
>Don't think I would hire a programmer who labels CGI programming as
>trivial. Likely his output would be trivial too. But maybe I am missing
>your point.
>
>--
>Toutatis




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

Date: Wed, 26 Nov 1997 21:23:22 -0800
From: "Matt Osborne" <mageos@hotmail.com>
Subject: Re: PERL Hourly Rates
Message-Id: <65j09e$d5u@dfw-ixnews12.ix.netcom.com>

I'm sure that this set of news is long dead, but I just subscribed.
before you hire a CGI programmer that claims to know perl, check to see what
other languages they know.  I am a senior in high school  and can program in
a variety of languages, not necessarily because I am smart but more because
once you learn the fundamentals of programming, such as objects or methods,
functions and procedures, arrays and types, you can "pick up" other
languages easier.  Before you hire someone, check there programming history.
Even though they will be programming CGI, the same kind of logic applies
that applies to regular programming.
Toutatis wrote in message ...
>comdog@computerdog.com (brian d foy) wrote:
>
>> In article <3475A7B3.819F9C2E@bridge.bellsouth.com>, Matthew Bonvicin
><Matthew.Bonvicin@bridge.bellsouth.com> wrote:
>>
>> >Could someone please provide for me an approximate hourly rate for
>> >advanced PERL CGI scripting.  I may have the need shortly to outsource
>> >some development but am unsure what to expect.
>>
>> CGI scripting is trivial.  if the programmer has other skills, then
>> you may have to pay more than minimum wage.
>
>Don't think I would hire a programmer who labels CGI programming as
>trivial. Likely his output would be trivial too. But maybe I am missing
>your point.
>
>--
>Toutatis




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

Date: Thu, 27 Nov 1997 06:56:26 GMT
From: wviecht@rs6000.cmp.ilstu.edu (Wolfgang Viechtbauer)
Subject: Please help with form script
Message-Id: <347d198a.264396@news.ilstu.edu>

Okay, simple script, but something does not seem to work. The script
only writes "9 9 9" into the data.txt file. The script worked fine on
a Win32 system, but now I am using it on a UNIX machine and it does
not work.


#! /usr/local/bin/perl
require("cgi-lib.pl");

open (DATA, ">>data.txt")
     || die ("Couldn't write to data file.\n");
&ReadParse;

print DATA (($in{question1} eq "") ? "9" : $in{question1});
print DATA " ",(($in{question2} eq "") ? "9" : $in{question2});
print DATA " ",(($in{question3} eq "") ? "9" : $in{question3}),"\n";
close DATA;


I have checked the names of the variables, so that is not the problem.
It must have something to do with the $in{var} eq "" thing ....  but I
can't figure it out.

Any comment or suggestions?

If possible, please send a copy of your reply to:

wviecht@rs6000.cmp.ilstu.edu

Thanks in advance,

Wolfgang



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

Date: Thu, 27 Nov 1997 04:18:08 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: reading a remote site's html?
Message-Id: <65jdfg$phc@bgtnsc03.worldnet.att.net>

In article <347CDA14.5A673C7A@prismrsc.com>, Jamie Gerdes
<jgerdes@prismrsc.com> wrote:

> I'd like to be able to read a remote html page
> (http://www.ANYSITE.com/index.htm) make some changes to it (or just get
> info from it) and then spit it back out from my CGI.  Can anyone PLEASE
> help me figure out how to read in a the remote page as if it were a file
> on my server?

take a look at the LWP module, especially LWP::Simple which has this
handy function get()

   #!/usr/bin/perl -w

   use LWP::Simple;

   my $source = get('http://www.perl.com');

   print $source;

   __END__

it's really that easy. :)  but if you really want to get crazy, you can
take a look at the Pelican book [1]

[1]
Web Client Programming in Perl
Clinton Wong
O'Reilly and Associates
<URL:http://www.oreilly.com>

-- 
brian d foy                                 <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm


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

Date: Thu, 27 Nov 1997 09:28:45 GMT
From: keith_willis.junk@non-hp-unitedkingdom-om1.om.hp.com (Keith Willis)
Subject: Re: Safe use of flock() -- was Re: giving up on flock
Message-Id: <347d3c8e.68986036@elf.bri.hp.com>

On 23 Nov 1997 17:14:49 -0500, Mark Mielke <markm@nortel.ca> wrote:

>Any ideas people? _SHOULD_ i be checking the return code of close() in
>C + perl scripts?Let's just say i wrote my code like this:
>
>--- CUT HERE ---
>use Fcntl qw(:flock);
>use IO::File;
>
>sub log
>{
>    my($path, $message) = @_;
>    my $handle = new IO::File($path, "a") ||
>        die "open of $path failed: $!\n";
>
>    flock($handle, LOCK_EX) ||
>        die "lock could not be obtained for $path: $!\n";
>
>    seek($handle, 0, SEEK_END) ||
>        die "seek-to-eof failed for $path: $!\n";

I am probably missing something here (and this is not related to the
subject of flock), but if you open the file with a type of "a", why
would you need to do a SEEK_END as well?

----------------------------------------------------------------------
The above message reflects my own views, not those of Hewlett Packard.
When emailing me, please note that there is no '.junk' in my address.


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

Date: 27 Nov 1997 12:06:56 GMT
From: "Greg McDermid" <mcdermidg@acm.org>
Subject: Re: Silly diamond operator (<>) problem?
Message-Id: <01bcfb35$3c3647c0$50ba0ccb@gregii>

Hi,

I tried your program and it worked, but I don't have a problem with @ARGV,
it is just the <> that causes me problems! E.g. I can use the following bit
of code:

foreach $file (<@ARGV>)
{
	open($file, $file);
	while (<$file>)
	{
		...
	}
	close($file);
}

don't laugh! it does work, but why can't I simply use:

while (<>)
{
	...
}


Regards,

Greg.

P.S. I use the standard NT shell (if you call it that - cmd.exe). I have a
perlglob.bat installed as part of the perl distribution, but not a
perlglob.exe - though that was part of the previous hip distribution.

I am using the standard CPAN distribution perl5_00402-bindist04-bc.zip.




Jonathan Feinberg <jdf@pobox.com> wrote in article
<MPG.ee6138dc8fd559d98969c@news.concentric.net>...
> [This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
> 
> mcdermidg@acm.org said...
> 
> > The problem is that if the input is a specified list of files, or
> > redirected input it works OK, but if I use wildcards it fails, e.g. 
perl
> > x.pl *.err, the error being like "Can't open *.err". Is there something
> > silly I missed here?
> 
> Sounds like whatever shell you're using isn't globbing.  I just tried
> the following program from my NT command shell
> 
>    #!perl -w
>    print join(" ", @ARGV), "\n";
> 
> and then invoked it from the command line thusly:
> 
>    perl foo.pl *.pl
> 
> and got the output
> 
>    foo.pl security.pl test.pl tree.pl
> 
> What do you get?  Are you using unnecessary quotes in your command line?
> 
> -- 
> Jonathan Feinberg    jdf@pobox.com    Sunny Brooklyn, NY
> 


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

Date: Wed, 26 Nov 1997 23:43:43 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Sorting an 'almost but not really' complicated data structure
Message-Id: <347CFA7F.A81@coos.dartmouth.edu>

Hans Juergen von Lengerke wrote:
> 
> # Sort: descending order for hit-count and ascending order for rest:
> @sorted_results_ref = sort &by_person (@results_ref);

Try it without the &:

@sorted_results_ref = sort by_person (@results_ref);

With the ampersand, you are calling &by_person(@results_ref), and then
sorting the result using the default sort function.

Chipmunk


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

Date: Thu, 27 Nov 1997 07:02:13 -0600
From: Martin Stitt <NOstitt@persoft.comSPAM>
Subject: Re: system vs. backtics.  What difference?
Message-Id: <347D6F55.F28C3BFD@persoft.comSPAM>

I use the bit of code below to launch a process and capture it's STDOUT
and
STDERR output to a file.  You could replace the "print" statement with a

"push" to capture the output into an array rather than write a file.

    my $sCommand = "foo/bar.exe";
    my $sCaptureFileName = "xyz.tmp";
    open(CAPTURE, ">$sCaptureFileName") || die "Error - Creating output
file: $sCaptureFileName.\n";
    open(PIPE, "$sCommand 2>&1 |");
    my $sOutput;
    while(sysread(PIPE, $sOutput, 2048)) {
        print CAPTURE $sOutput;
    }
    close(CAPTURE);
    close(PIPE);

Will "sysread()" under Win95 deal with slashes of either direction,
like system() does?  Haven't a clue -- don't use that OS.


Hope this helps...




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

Date: Thu, 27 Nov 1997 11:37:02 +0100
From: David Bouman <david@hq.tip.nl>
Subject: Re: trouble with libwww & friends in nonstandard libdir. alternatives to libwww ?
Message-Id: <347D4D4E.1A73@hq.tip.nl>

Michael A. Chase wrote:

> You may have a perl that doesn't allow dynamic loading of modules. I 
> was
> just bit by this yesterday.  Try this to see if you have the same
> problem:
> 
> perl -we 'use IO::Socket;'

Actually I'm pretty sure my local perl installation does support
dynamic loading. 'make test' did pass all tests when I installed the
IO bundle. But I'll try:

$ perl5 -I/mypath/lib -we 'use IO::Socket' 
Can't find loadable object for module IO in @INC (/mypath/lib
/volume/perl5/lib/sun4-solaris/5.003 /volume/perl5/lib
/volume/perl5/lib/site_perl/sun4-solaris /volume/perl5/lib/site_perl .)
at /mypath/lib/IO.pm line 13
BEGIN failed--compilation aborted at /mypath/lib/IO/Handle.pm line 232.
BEGIN failed--compilation aborted at /mypath/lib/IO/Socket.pm line 12.
BEGIN failed--compilation aborted at -e line 1.
$

Hmm, that does give me a clue however:

$ perl5 -I/mypath/lib -I/mypath/lib/sun4-solaris/5.003 -we 'use
IO::Socket' 
$

So that's it perhaps, but it sure is unwieldy. Isn't there a
more elegant way to do this ? 

I got libnet to install now: I edited the Configure script to
include:

use lib '/mypath/lib';
use lib '/mypath/lib/sun4-solaris/5.003';

_And_ I still had to do:

perl5 -I/mypath/lib -I/mypath/lib/sun4-solaris/5.003 Makefile.PL
PREFIX=/mypath


So I guess my question boils down to: Do I have to add '/mypath/lib'
to the @INC list AS WELL AS it's 'sun4-solaris/5.003' subdir? I
would think that that information should be configured into IO.pm
when it was installed in '/mypath/lib'.  Or am I asking too much ?


--
David Bouman (david@hq.tip.nl)


> David Bouman wrote in message <347968A8.1E0A@hq.tip.nl>...
>
> >I'm trying to install libwww (5.15) and all it's needed companions:
> >IO-1.1802, MD5-1.7, MIME-Base64-2.03 and libnet-1.0602. I'm currently
> >blessed with a perl v5.0003 installation that lacks the required IO
> >bundle. Being a non-priviledged user I installed the IO bundle in a
> >non-standard lib directory of my own. So far so good. Next I tried to
> >installing the libnet bundle, thinking a
> >
> >'perl5 -I<my-libdir> Makefile.PL PREFIX=<my-lib-basedir>'
> >
> >would do the trick. This however does not work, neither do several
> >other variations i've tried to manipulate the @INC list. It keeps
> >complaining with a
> >
> >'Can't locate IO/File.pm in @INC at Configure line 6.'


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

Date: Thu, 27 Nov 1997 01:41:49 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: truncating a string
Message-Id: <347D162C.5B4A@coos.dartmouth.edu>

Bill Eberle wrote:
> 
> I have a problem with limiting the size of a string variable.  I want to
> take the first ten characters and delete the rest.  Does anyone know an
> easy way to do this, short of reading the first ten characters into an
> array?  Thanks.

The easiest way I know:

substr($str, 10) = '';

Look up substr in the perlfunc manpage for more info.

Chipmunk


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

Date: 27 Nov 1997 11:27:30 GMT
From: "Robert Friberg" <robert.friberg@your_clothes.eductus-vast.com>
Subject: Re: Variable Pattern Options
Message-Id: <01bcfb26$b9b1d660$c82da8c0@akilles.ittek.org>

Greg Derzay writes:
> In a Perl script, I'd like to have the following statement:
> 
> @matches = ($lines =~ /$pattern/$options);
>   
> However, the compiler will not allow me to use the $options variable.
> I am using Perl version 5.004_01.  It has no problem with using 
> a variable for the pattern, but chokes on the variable for the 
> options.  Why can't I do this?  I'm trying to write a UNIX script
> to perform grep-like things in Perl, and need to have dynamic 
> options in pattern matching.

I tried using eval and it works for me under linux with perl 5.003
If it's a good thing or a bad thing is another question.

#!/usr/bin/perl -w
$options = 'i';
$exp = '^TesT';
$line = 'testing eval';
eval "\$line =~ /$exp/$options";

or 

#!/usr/bin/perl -w
$options = 'ig';
$exp = '([a-z])\1';
$_ = 'BOOKKEEPERS OF MISSISSIPPI';
eval "s/$exp/\$1/$options";
print "$_\n";

-- 
Hope this helps,
robban
robert.friberg(a)eductus-vast.com


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 1381
**************************************

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