[25694] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7935 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 2 14:05:39 2005

Date: Sat, 2 Apr 2005 11:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 2 Apr 2005     Volume: 10 Number: 7935

Today's topics:
        #!perl  ?? <jkrugman345@yahbitoo.com>
    Re: #!perl  ?? <tintin@invalid.invalid>
    Re: #!perl  ?? <xx087@freenet.carleton.ca>
    Re: #!perl  ?? <tadmc@augustmail.com>
    Re: $line = <FH> returns incomplete lines axel@white-eagle.invalid.uk
    Re: $line = <FH> returns incomplete lines <nobull@mail.com>
    Re: CD-R or CD-RW ? <tassilo.von.parseval@rwth-aachen.de>
    Re: Database -> Excel <dontwannasay@home.com>
    Re: difference between two files <hendrik_maryns@despammed.com>
    Re: difference between two files <theaney@cablespeed.com>
    Re: difference between two files <hendrik_maryns@despammed.com>
    Re: FAQ 5.17 How can I open a file with a leading ">" o <nobull@mail.com>
        multiple changes on multiple lines (Dave)
    Re: multiple changes on multiple lines <noreply@gunnar.cc>
        To change the time stamp format... clearguy02@yahoo.com
    Re: To change the time stamp format... <felix.geerinckx@gmail.com>
    Re: To change the time stamp format... <noreply@gunnar.cc>
    Re: To change the time stamp format... clearguy02@yahoo.com
    Re: To change the time stamp format... <noreply@gunnar.cc>
    Re: Unable to connect to remote host <srithota@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 2 Apr 2005 07:37:30 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: #!perl  ??
Message-Id: <d2li3q$qte$1@reader1.panix.com>



I've seen code that starts with the line

#!perl

but when I try the same thing myself, I get a 'bad interpreter'
error.  And yet, something like this:

% perl -le 'print "hello"'

works perfectly.  What do I have to do to use #!perl (instead of
a fully qualified path) as my shebang line?

TIA!

jill
-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: Sat, 2 Apr 2005 20:08:16 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: #!perl  ??
Message-Id: <Pps3e.14967$1S4.1557703@news.xtra.co.nz>


"J Krugman" <jkrugman345@yahbitoo.com> wrote in message 
news:d2li3q$qte$1@reader1.panix.com...
>
>
> I've seen code that starts with the line
>
> #!perl

Which does nothing on Windows systems, or the below error on Unix systems.

Note, that any perl switches will be recognised on Windows systems.

>
> but when I try the same thing myself, I get a 'bad interpreter'
> error.

As to be expected on Unix systems.  You need to use the absolute path to 
perl.

>And yet, something like this:
>
> % perl -le 'print "hello"'

The shell searches the directories in the PATH environment variable to find 
where perl is.

>
> works perfectly.  What do I have to do to use #!perl (instead of
> a fully qualified path) as my shebang line?

Either use Windows, or call the script directly with perl, eg:

perl yourscript.pl




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

Date: 2 Apr 2005 14:51:10 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: #!perl  ??
Message-Id: <slrnd4tcav.l.xx087@smeagol.ncf.ca>

At 2005-04-02 02:37AM, J Krugman <jkrugman345@yahbitoo.com> wrote:
[...]
>  What do I have to do to use #!perl (instead of
>  a fully qualified path) as my shebang line?

use the env utility:
    #!/usr/bin/env perl

unless you also need to use -T in which case use a fully qualified path
to perl.

see also http://www.spanner.org/lists/osxperl/2005/02/21/bd5a5153.html

-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: Sat, 2 Apr 2005 07:46:19 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: #!perl  ??
Message-Id: <slrnd4t8hb.54c.tadmc@magna.augustmail.com>

J Krugman <jkrugman345@yahbitoo.com> wrote:
> 
> I've seen code that starts with the line
> 
> #!perl


If run on Windows, you could put command line switches on that
line and they would be recognized.


> but when I try the same thing myself, I get a 'bad interpreter'
> error.


If run on *nix, you get that error message.


> What do I have to do to use #!perl (instead of
> a fully qualified path) as my shebang line?


Why do you think you want to use #!perl (instead of a fully 
qualified path) as your shebang line?

That is, what problem are you hoping to overcome by being able
to do what you've asked?

If we knew that, we might be able to suggest an alternative.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 02 Apr 2005 02:22:42 -0600
From: axel@white-eagle.invalid.uk
Subject: Re: $line = <FH> returns incomplete lines
Message-Id: <0vidnXVqnOPPy9PfRVn-oQ@adelphia.com>

Brian McCauley <nobull@mail.com> wrote:
> axel@white-eagle.invalid.uk wrote:
>> The following seems to work. 

>> #!/usr/bin/perl
>> 
>> open (MYLOG, "/tmp/mylog") or die "Cannot open file: $!";
>> $|++;
>> 
>> print "GOT THIS: ";
>> while ( 1 ) {
>>     while (<MYLOG>) {
>>         print;
>>         print ("GOT THIS: ") if /\n/;
>>     }  
>>     sleep (1);
>> }
>> __END__
 
> That is missing the seek() that is needed to reset the EOF flag on MYLOG.
> If you insert the seek() it will work, sort of, but only because you are 
> simply printing the output. 

It works without the seek. Each time some characters are picked up
they are printed. A new 'GOT THIS' message is only printed once a
new line is seen in the input (actually it should not be printed
until at least something has actually been received).

> If you wanted to do someting else - like 
> selectively print lines by pattern match (as per OP) then it wouldn't work.

I find that it does...  a slightly altered version with a couple of
pattern matching examples...

1) An specific error message is printed once a full line (i.e.
   terminated by \n) is found to contain 'error'.
2) A critical message is printed immediately the incoming line is
   found to contain 'critical' - there is no wait for the end of
   line (the message is repeated as the line is built up until
   terminated by \n).

#!/usr/bin/perl

use warnings;
use strict;

open (MYLOG, "/tmp/mylog") or die "Cannot open file: $!";
$|++;

my $line;
my $prefix = "GOT THIS: ";
print "Listening\n";
while ( 1 ) {
    while (<MYLOG>) {
        print $prefix, $_;
        $prefix = '';
        $line .= $_;

        print "\nCritical *************\n" if $line =~ 'critical';
        print "Error =============\n" if /\n/ && $line =~ 'error';

        if (/\n/) {
            $prefix = 'GOT THIS: ';
            $line = '';
        } else {
            $prefix = '';
        }
    }
    sleep (1);
}
__END__


Axel




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

Date: Sat, 02 Apr 2005 09:21:11 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: $line = <FH> returns incomplete lines
Message-Id: <d2lnr9$bte$1@sun3.bham.ac.uk>



axel@white-eagle.invalid.uk wrote:

> Brian McCauley <nobull@mail.com> wrote:
> 
>>axel@white-eagle.invalid.uk wrote:
>>
>>>The following seems to work. 
 >>
>>That is missing the seek() that is needed to reset the EOF flag on MYLOG.
 >
 > It works without the seek.

I think you were right the first time. It _seems_ to work.  My 
understanding  is that it is undefined if Perl's readline() will or will 
not reset the EOF condition when more data appears in a file.

Right now I can't find a platform on which your code fails but so long 
as it is officially undefined if it will work without the seek() I'd be 
inclined not to omit it.

>>it will work, sort of, but only because you are 
>>simply printing the output. 
> 
> Each time some characters are picked up they are printed.

Yes, that was my point.  You rely on the behaviour of the output device 
to give the false impression that split lines are being reassembled. 
(Note reassembly of the split lines is the subject of this thread).

>>If you wanted to do someting else - like 
>>selectively print lines by pattern match (as per OP) then it wouldn't work.
> 
> 
> I find that it does...  a slightly altered version

>         $line .= $_;

>         if (/\n/) {
>             $line = '';
>         }

Well, yes, of course, if you add the code that reassembles split lines 
then of course your solution is the same as all the others offered in 
this thread. (Remember, it is the reassembly of the split lines that is 
the subject of this thread).



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

Date: Sat, 2 Apr 2005 08:29:20 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: CD-R or CD-RW ?
Message-Id: <slrnd4seu0.t5.tassilo.von.parseval@localhost.localdomain>

Also sprach Brian McCauley:

> kielhd wrote:
>
>> is there a way for Perl to find out, if a CD is a CD-R or a CD-RW?
>
> If your operating system provides and interface that makes this 
> information available to applications then no doubt you can get at it 
> with Perl.
>
> For example on Unix-like OSs there's probably an IOCTL you can use on 
> the device file correspoding to the CD.

Is the OP talking about the disc or the drive? Linux (and therefore
Solaris probably too) has the CDROM_GET_CAPABILITY ioctl which, among
other things, tells whether a drive can write CD-Rs, CD-RWs, DVD-Rs
and/or DVD-RWs. But I know of no ioctl that would tell me whether an
inserted disc is CD-R or CD-RW. 

Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


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

Date: Sat, 02 Apr 2005 10:57:44 -0600
From: Mike <dontwannasay@home.com>
Subject: Re: Database -> Excel
Message-Id: <Xns962C5B2BD73E2dontwannasaycom@216.196.97.136>

Robert <sigzero@gmail.com> wrote in news:sigzero-06C786.22411331032005
@news.isp.giganews.com:

> I see a whole passle of Excel modules on CPAN. I am querying an Oracle 
> database and I want to save that query into an Excel file. What module 
> would you suggest that I use?
> 
> Robert

I think I'm doing this very same thing.  I'm using Spreadsheet-WriteExcel,
DBI, and DBD-Oracle.  I'm creating the spreadsheet on HP-UX and sending
it out via e-mail to the interested parties.

Cheers,
Mike


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

Date: Sat, 02 Apr 2005 12:26:18 +0200
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Re: difference between two files
Message-Id: <1112437609.496380@seven.kulnet.kuleuven.ac.be>

A. Sinan Unur schreef:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
> news:d2jgb2$ksu$1@mamenchi.zrz.TU-Berlin.DE: 
> 
> 
>>Tim Heaney  <tim@mrbun.watterson> wrote in comp.lang.perl.misc:
>>
>>>anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>>>
>>>>The algorithm in diff to produce a line-by-line comparison of files
>>>>is remarkably complex 
> 
> 
> ...
> 
>>>The CPAN module Algorithm::Diff seems to do all that and more. If you
>>>really want just diff, the Text::Diff module distills it for you.
> 
> 
> ...
> 
> 
>>Thanks for the correction.  I never noticed those modules.
> 
> 
> OTOH, the OP might want to remember that XML files can have equivalent 
> data, but not the same text.

Thanks all!

Looks like I have to install Linux soon... (was planning that anyway)

And no, I don't care about equivalence, but thanks for pointing that out.

I'll have a look on Text::Diff!

H.

-- 
Hendrik Maryns

Interesting websites:
www.lieverleven.be	(I cooperate)
www.eu04.com		European Referendum Campaign
aouw.org		The Art Of Urban Warfare


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

Date: Sat, 02 Apr 2005 08:22:00 -0500
From: Tim Heaney <theaney@cablespeed.com>
Subject: Re: difference between two files
Message-Id: <87zmwhxqiv.fsf@mrbun.watterson>

Hendrik Maryns <hendrik_maryns@despammed.com> writes:
>
> Looks like I have to install Linux soon... (was planning that
> anyway)

Far be it from me to recommend against this (Linux is my preferred
platform), but you can use both command-line diff

  http://gnuwin32.sourceforge.net/packages/diffutils.htm

and Perl's Text::Diff (and Algorithm::Diff on which it depends) from
Windows. The diff command would be identical

  diff -U3 file1.xml file2.xml

and the Perl command would require double-quotes instead of single

  perl -MText::Diff -e "print diff @ARGV" file1.xml file2.xml

There are lots of good reasons to switch to Linux; requiring diff is
not one of them.

Tim


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

Date: Sat, 02 Apr 2005 15:48:53 +0200
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Re: difference between two files
Message-Id: <1112449764.5473@seven.kulnet.kuleuven.ac.be>

Tim Heaney schreef:
> Hendrik Maryns <hendrik_maryns@despammed.com> writes:
> 
>>Looks like I have to install Linux soon... (was planning that
>>anyway)
> 
> 
> Far be it from me to recommend against this (Linux is my preferred
> platform), but you can use both command-line diff
> 
>   http://gnuwin32.sourceforge.net/packages/diffutils.htm
> 
> and Perl's Text::Diff (and Algorithm::Diff on which it depends) from
> Windows. The diff command would be identical
> 
>   diff -U3 file1.xml file2.xml
> 
> and the Perl command would require double-quotes instead of single
> 
>   perl -MText::Diff -e "print diff @ARGV" file1.xml file2.xml

Thanks fot this one.  I really have to learn to write oneliners.  All 
these four-line scripts aren't very useful & handy anyway.
> 
> There are lots of good reasons to switch to Linux; requiring diff is
> not one of them.

Of course it isn't, but I was going to do it anyway, after the supplier 
has fixed some stuff that they promised to do but didn't.

Cheers, H.
-- 
Hendrik Maryns

Interesting websites:
www.lieverleven.be	(I cooperate)
www.eu04.com		European Referendum Campaign
aouw.org		The Art Of Urban Warfare


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

Date: Sat, 02 Apr 2005 12:20:15 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: FAQ 5.17 How can I open a file with a leading ">" or trailing blanks?
Message-Id: <d2m2b3$gr8$1@sun3.bham.ac.uk>



PerlFAQ Server wrote:

> 5.17: How can I open a file with a leading ">" or trailing blanks?
> 
>     Normally...  [behaviour of 2-arg open() ]

I think the time has long passed when the 2-arg open could be considered 
normal.

It would now be more appropriate to say open() _normally_ takes three or 
more arguments but that mostly historical reasons the second and 
subsequent arguments can be combined into a single argument.

>     It may be a lot clearer to use sysopen(), though:

But it probably won't, so better not to mention it really.



5.17: How can I open a file with a leading ">" or trailing blanks?

     The special two argument form of Perl's open() function ignores
     trailing blanks in filenames and infers the mode from certain
     leading characters (or a trailing "|").

     In older versions of Perl this was the only version of open() and
     so it is prevalent in old code and books.

     Unless you have a particular reason to use the two argument form
     you should use the three argument form of open() which does not
     treat any charcters in the filename as special.



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

Date: 2 Apr 2005 08:42:31 -0800
From: fxman1@hotmail.com (Dave)
Subject: multiple changes on multiple lines
Message-Id: <70ddd040.0504020842.1abc251b@posting.google.com>

Hello

I would appreciate tips where I can find a base for re programming or
where a can buy perl script with this functions

I have a file that need multiple changes on multiple lines


replaceblock.pl FileToChange.txt blockreplace.txt

example FileToChange.txt 

line 1 /*
line 2 [00.893]
line 3 text2
line 4 text3
line 5 /* explanation
line 6 /* text
line 7 text [0.456.] text
line 8 text8
line 9      test ("text9"), text [35.989 , 67.88 , 33.02]
line 10     text text text
line 11     text [2.5] text
line 12 text 55
line 13 text and numbers with programming symbols....
line 14 text14

example blockreplace.txt

[start block] /* replacing line 2 and 3
 [00.893]
 text2
[end block]
[start replace block]
 [2.15]
 text2 with more text
[end replace block]

[start block] /* replacing line 9, 10 and 11
 test ("text9"), text [35.989 , 67.88 , 33.02]
 text text text
 text [2.5] text
[end block]
[start replace block]
 test ("texzz9"), tezz [15.00 , 60.00 , 30.00]
 tezz tezz tezz
[end replace block]

[start block]...... "numbers of blocks change from file to file"


newbie in perl

Ihave made a script 7 years ago, and havent used perl since.

Thanks 

/Dave


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

Date: Sat, 02 Apr 2005 19:06:45 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: multiple changes on multiple lines
Message-Id: <3b81mhF6h7sg3U1@individual.net>

Dave wrote:
> I would appreciate tips where I can find a base for re programming

     http://learn.perl.org/

> or where a can buy perl script with this functions

     http://www.google.com/

(but I doubt you'll find anything)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 2 Apr 2005 09:01:04 -0800
From: clearguy02@yahoo.com
Subject: To change the time stamp format...
Message-Id: <1112461264.799057.147850@f14g2000cwb.googlegroups.com>

Hi experts,

I need a function in my perl program that converts the given time stamp
to a specific time stamp format.

example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00

Can some one tell me how to do this?

Thanks,
John



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

Date: Sat, 02 Apr 2005 17:19:11 GMT
From: "Felix Geerinckx" <felix.geerinckx@gmail.com>
Subject: Re: To change the time stamp format...
Message-Id: <xn0e0j5gl1frawi000@news.easynews.com>

On 02/04/2005, clearguy02@yahoo.com wrote:

> example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00
> 
> Can some one tell me how to do this?

use split with /[-:.]/ to get the individual date parts
use a hash to translate month abbreviations to month numbers
use sprintf to format your target date

-- 
felix


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

Date: Sat, 02 Apr 2005 19:27:03 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: To change the time stamp format...
Message-Id: <3b82smF69js0nU1@individual.net>

clearguy02@yahoo.com wrote:
> I need a function in my perl program that converts the given time stamp
> to a specific time stamp format.
> 
> example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00
> 
> Can some one tell me how to do this?

There are two approaches:

1) You can search for an applicable module at http://search.cpan.org/

2) You can write the function yourself. Useful built-in Perl functions
    may be:

     perldoc -f split
     perldoc -f sprintf

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 2 Apr 2005 10:04:28 -0800
From: clearguy02@yahoo.com
Subject: Re: To change the time stamp format...
Message-Id: <1112462689.316712.235190@f14g2000cwb.googlegroups.com>

Thanks Felix,

Do you have any example code to do this?

Thanks,
John



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

Date: Sat, 02 Apr 2005 20:59:18 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: To change the time stamp format...
Message-Id: <3b88afF6eos6sU1@individual.net>

[ Please give some context when you reply to a message. See the posting 
guidelines for this group at 
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html ]

clearguy02@yahoo.com wrote:
> Felix Geerinckx wrote:
>>> 
>>> example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00
>>>
>>> Can some one tell me how to do this?
>> 
>> use split with /[-:.]/ to get the individual date parts
>> use a hash to translate month abbreviations to month numbers
>> use sprintf to format your target date
> 
> Thanks Felix,
> 
> Do you have any example code to do this?

Felix probably has code in his collection of Perl code snippets that 
does exactly the convertion you need, and it was most likely through an 
oversight he didn't post it along with the above hints.

If I'm wrong in my assumption, you may need to look up those parts of 
the Perl documentation and give it a try yourself. Scaring thought, I 
know, but what can you do...

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 2 Apr 2005 10:59:51 -0800
From: "sri" <srithota@gmail.com>
Subject: Re: Unable to connect to remote host
Message-Id: <1112468391.544649.261610@f14g2000cwb.googlegroups.com>

Thanks for the tip..

I insterted $^E alongside $!. It gave me much more info....

Error is "The requested service provider could not be loaded or
initialized" . I googled this error and found that its something to do
with winsock. I could not find a solution though. Do you have any
suggestion?

Thanks for your help !!

- Srini



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V10 Issue 7935
***************************************


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