[12169] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5769 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 25 04:07:28 1999

Date: Tue, 25 May 99 01:00:24 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 25 May 1999     Volume: 8 Number: 5769

Today's topics:
    Re: @INC  - Require Problem (Tad McClellan)
    Re: @INC  - Require Problem <abey@cs.ucr.edu>
        accessing C++ object data <brad@wcubed.net>
    Re: conditional regexp matching. Please advise. (Ilya Zakharevich)
        Finding the date... <nick@auger.net>
    Re: Finding the date... (Dave Cross)
        help on openiong and manipulating files <reese@value.net>
    Re: help on openiong and manipulating files <brent.s@ihug.co.nz>
    Re: help on openiong and manipulating files (Dave Cross)
        Help Requested with PERL script <dwinet@transbay.net>
        Ho to get started with Tk on Win32? <leonandrews@my-dejanews.com>
        How do i add two values? <poohba@io.com>
    Re: How do i add two values? (Dave Cross)
        How to embed perl into Win32 applications? <sauli.karhu@lmf.ericsson.se>
        Interesting question billy_collins@my-dejanews.com
    Re: Mod of large number (Marko R. Riedel)
    Re: Newbie  Perl --> HTML (Dave Cross)
    Re: Pigheadedness (was Re: Newbie; Perl/Tk Event models (Larry Rosler)
        Please, why -w file test does not work? <pkotala@logis.cz>
        Printers (Arthur Merar)
        re-webifying strings for GET methods younggs@acwilm.com
        s/// multiple lines in file from cmd line <otis@my-dejanews.com>
    Re: s/// multiple lines in file from cmd line <uri@sysarch.com>
        String search problem (Raul R Ramirez)
    Re: String search problem (Sam Holden)
    Re: The docs as talking books (was Re: newbie with a "h (Marcel Grunauer)
        Uploading file and e-mailing it using Perl (Mark Thompson)
    Re: using gethostbyaddr? (Larry Rosler)
        Writing data to: /dev/$DEV <edsys@my-dejanews.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Mon, 24 May 1999 18:52:25 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: @INC  - Require Problem
Message-Id: <97lci7.fkj.ln@magna.metronet.com>

Mike Hagstrom (mch@publinx.com) wrote:

: I'm new to the group, and this is my first posting, so please bear with me.

: I'm attempting to port a UNIX Perl program for use on NT Server. The
: overall program contains a number of ".cgi" files which require the module
: "options.pm". One file, "start.cgi" This file and the other ".cgi" files
: all contain the following opening two lines

: unshift (@INC, ".");
: require (options); 

: Here's the issue: the files seem to run OK from a command prompt. However,
: if I attempt to call the ".cgi" files from an HTML page


   Whenever you find yourself writing that, you should know that
   you do not have a Perl problem.

   Perl works. You said so. So posting to the Perl newsgroup
   is the wrong place.

   If it fails to function in a different environment, then it
   is likely due to something in the environment.

   For what might be different in a WWW environment, please
   ask in a newsgroup that is connected to WWW stuff in some
   way. This is not such a newsgroup.

      comp.infosystems.www.authoring.cgi
      comp.infosystems.www.servers.ms-windows


   Your statement above nearly matches this Perl FAQ, from part 9:

      "head2 My CGI script runs from the command line but not the browser.
       (500 Server Error)"

   which has several URLs that may help with using Perl for
   CGI programming.


: I get the following error message:

: Can't locate options.pm in @INC at


: Any ideas or suggestions?


   Sounds like the current directory is different in the two
   environments.

   Try using an absolute path, or chdir(), or copy the .pm files
   to the correct place, or ...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Mon, 24 May 1999 23:34:58 -0800
From: Abraham Grief <abey@cs.ucr.edu>
Subject: Re: @INC  - Require Problem
Message-Id: <927617700.22782@www2.remarq.com>


Sorry if this gets posted multiple times, I'm having news
problems.

It's probably because when you get your webserver to run
the program, it
runs in taint mode.  I'm not sure what is tainted about
'unshift (@INC, ".");', and I guess someone else can say
why, I just know
it doesn't work in taint mode.  Just change  all of your
lines
that say

unshift (@INC, ".");

into

use lib '.';

and you should be fine.  Hope this helps.




**** Posted from RemarQ - http://www.remarq.com - Discussions Start Here (tm) ****


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

Date: Mon, 24 May 1999 23:20:46 -0600
From: Brad Waite <brad@wcubed.net>
Subject: accessing C++ object data
Message-Id: <374A332E.B917BF12@wcubed.net>

Is there a way to access the data in a C++ object?

In my case, I'm dealing with GD.pm.  When I do this:

	$image = newFromGif GD::Image('FH');

it passes the filehandle FH to _newFromGif (which, I'm assuming, is the
C++ function/method).  A pointer (gdImagePtr) to the gdImage structure
(gdImageStruct) is returned to GD.pm, which then returns it to the
caller.

Is there a way to dereference that pointer all the way to the C++
structure?  I'm asking (for those who haven't read my 10+ previous
posts), because I want to freeze the GD::Image object to pass to another
process via IPC calls.  Passing only the pointer is pointless (PI) since
the object referenced only exists in the first program.  So I need to be
able to freeze the actual data, which in this case is created in the C
lib.

Or do I have to add a new method to the original gd library and the perl
module?

Or is there a better way to pass a gif image between two processes?

-Brad


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

Date: 25 May 1999 06:22:02 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: conditional regexp matching. Please advise.
Message-Id: <7idfia$ptr$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Ronald J Kimball
<rjk@linguist.dartmouth.edu>],
who wrote in article <1dsbsk6.1p2pqs013ii41sN@p112.block2.tc1.state.ma.tiac.com>:
> > "Work better"?  It is not clear what you mean here.  I assume "look
> > better".  
> 
> Also "more efficient", as implied in the previous sentence. 

Nope, exactly the opposite.

> /dog/ and /cat/ and !/bird/
> 
> vs.
> 
> /^(?=.*dog)(?=.*cat)(?!.*cat)/
> 
> I definitely prefer the first in this case.

Of course, you may prefer whatever you like.  My pennies:

    a) You are comparing apples and oranges.  Since the RExen in the
       first example are optimized away, your first example may be
       indeed quickier than the second one.  Put something more
       complicated there, and you will probably get an opposite
       result. 

       AFAIU, entering/exiting REx engine is very expensive, so
       anything which improves on this will lead to better performance.

    b) If the second REx is not anchored, but is a part of a larger
       backtracking REx, you cannot substitute it with the first one.

Ilya


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

Date: Mon, 24 May 1999 20:10:56 -0400
From: nick <nick@auger.net>
Subject: Finding the date...
Message-Id: <3749EA8F.1A24F582@auger.net>

How can I find what day it was 7 days ago?  If I use $day =
(localtime(time))[3];, I can get todays date, and subtracting 7 from it
will give me the date 7 days ago. But what if it is the 5th, then after
subracting 7, it will give me -2.  Is there an easy way to do this?  Or
am I gonna have to create a whole subroutine?  Thanks in advance for
help.

Nick Auger

======================================
  Sk8punk's In-line Domain - http://sk8punk.otmi.com
======================================



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

Date: Tue, 25 May 1999 07:41:51 GMT
From: dave@dave.org.uk (Dave Cross)
Subject: Re: Finding the date...
Message-Id: <374d5133.54582229@news.demon.co.uk>

On Mon, 24 May 1999 20:10:56 -0400, nick <nick@auger.net> wrote:

>How can I find what day it was 7 days ago?  If I use $day =
>(localtime(time))[3];, I can get todays date, and subtracting 7 from it
>will give me the date 7 days ago. But what if it is the 5th, then after
>subracting 7, it will give me -2.  Is there an easy way to do this?  Or
>am I gonna have to create a whole subroutine?  Thanks in advance for
>help.

The Date::Manip module from CPAN <http://www.cpan.org> will allow you
to do all of those kinds of things very easily.

If you're stuck with the standard Perl distribution than this snippet
of code will add (or subtract) a given number of days from the current
date and time.

use Time::Local;

my $delta; # Number of days to add or subtract (-ve for substractions)
my @now = localtime;
my @then = @now;

# Adjust to midday to avoid errors with DST
@then[0 .. 2] = (0, 0, 12);
my $then = timelocal(@then[0 .. 5]);

# Add or subtract the relevant number of days
$then += ($delta * 23 * 60 * 60);

@then = localtime($then);
# Restore original time
@then[0 .. 2] = @now[0 .. 2];

At the end of this code, @then will contain all of the various parts
of the the data and time as you would get from localtime.

Dave...

--
Dave Cross <dave@dave.org.uk>
<http://www.dave.org.uk>


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

Date: Mon, 24 May 1999 21:41:01 -0700
From: Reese Butler <reese@value.net>
Subject: help on openiong and manipulating files
Message-Id: <374A29DD.1BBE@value.net>

Im triying to open a simple .txt file and store txt into variables
using code from a tutorial book that goes like so

#!/usr/bin/perl

print "Content-type: text/html\n\n";



open(dbtest, "http://www.server.com\Hank\db.txt");

select(dbtest);
while (<dbtest>) {

chop;

($item, $price) = split(/:/,$_,2);
$price_list{item} = $price;


}
close ( dbtest );

this much of the code works, however when i try to print a variable i
get nothing, as if its not reading anything at all.
the book says to use: open($filehandle, "url");
but when i use the $ sign i get an error. why is this, and why wont my
code read any of db.txt into the $price_list array?
db.txt is as follows

item:price
name1:test1
name2:test2
name3:test3

any assistance is greatly appreciated

-Hank


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

Date: Tue, 25 May 1999 17:50:09 +1200
From: Brent Singers <brent.s@ihug.co.nz>
Subject: Re: help on openiong and manipulating files
Message-Id: <Pine.LNX.4.10.9905251730350.2500-100000@brent.ihug.co.nz>

> Im triying to open a simple .txt file and store txt into variables
> using code from a tutorial book that goes like so

Woohoo!  Another post I can deal with :)

> #!/usr/bin/perl

No doubt that at some stage someone will tell ya that you should be using
-w after that.

> open(dbtest, "http://www.server.com\Hank\db.txt");

You can specify the url like that?  I thought you had to specify the path
on the server machine itself....
 
> select(dbtest);
> while (<dbtest>) {
> 
> chop;
> 
> ($item, $price) = split(/:/,$_,2);
> $price_list{item} = $price;
> 
> 
> }
> close ( dbtest );

May I suggest the following?  It works fine for me (with -w and using
strict) ...

open(FILE,"db.txt");
while ( defined a$(line = <FILE>) ) {
  chop $line;
  (@price_list) = split(/:/, $line);
  # code galore goes in here
}
close(FILE);

That will leave you with an array with the two values from each line in
the array.  Deal with those two and then it goes onto the next line.

> the book says to use: open($filehandle, "url");
> but when i use the $ sign i get an error. why is this,

'Coz they screwed up?

Brent

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  /"\
  Why is it lemon juice contains mostly          \ / ASCII RIBBON CAMPAIGN
  artificial ingredients, but dishwashing         X  AGAINST HTML EMAIL
  liquid contains real lemons?                   / \
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=




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

Date: Tue, 25 May 1999 07:49:15 GMT
From: dave@dave.org.uk (Dave Cross)
Subject: Re: help on openiong and manipulating files
Message-Id: <374f5536.55609884@news.demon.co.uk>

On Mon, 24 May 1999 21:41:01 -0700, Reese Butler <reese@value.net>
wrote:

>Im triying to open a simple .txt file and store txt into variables
>using code from a tutorial book that goes like so
>
>#!/usr/bin/perl
>
>print "Content-type: text/html\n\n";
>
>
>
>open(dbtest, "http://www.server.com\Hank\db.txt");
>
>select(dbtest);
>while (<dbtest>) {
>
>chop;
>
>($item, $price) = split(/:/,$_,2);
>$price_list{item} = $price;
>
>
>}
>close ( dbtest );
>
>this much of the code works, however when i try to print a variable i
>get nothing, as if its not reading anything at all.
>the book says to use: open($filehandle, "url");
>but when i use the $ sign i get an error. why is this, and why wont my
>code read any of db.txt into the $price_list array?
>db.txt is as follows
>
>item:price
>name1:test1
>name2:test2
>name3:test3
>
>any assistance is greatly appreciated

you're pasing a URL to open, and open doesn't understand URLs, only
file paths. If you *really* want to get your data from a URL, you
should be looking at the LWP bundle of modules that you can get from
CPAN, <http://www.cpan.org>,

Dave...

--
Dave Cross <dave@dave.org.uk>
<http://www.dave.org.uk>


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

Date: Tue, 25 May 1999 00:15:27 -0700
From: David Winet <dwinet@transbay.net>
Subject: Help Requested with PERL script
Message-Id: <374A4E0F.640BDB9B@transbay.net>

I need to cut up a large file of email addresses into smaller files,
then send each smaller files to each of the addresses it contains.
(I'm trying to break up a large online class into dicussion groups this
way)
Any help appreciated! My PERL skills are limited to modifying not
creating scripts. Thanks!
dwinet@transbay.net


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

Date: Tue, 25 May 1999 07:00:54 GMT
From: Leon <leonandrews@my-dejanews.com>
Subject: Ho to get started with Tk on Win32?
Message-Id: <7idhr6$aeg$1@nnrp1.deja.com>

Hi,

Can anyone point me to any examples of how to get started with Tk?

I have all of the modules, but there don't seem to be any demo programs
to try. Also, do I need to install any more software to get Tk to make
windows Apps? Will a simple "hello world" type of program written in
Perl using Tk fire up a Windows window?

many thanks,

Leon.


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: Tue, 25 May 1999 00:47:05 -0500
From: Poohba <poohba@io.com>
Subject: How do i add two values?
Message-Id: <Pine.BSF.4.05.9905250042460.861-100000@schultz.io.com>

I am trying to add two values from the same field but on different arrays.
I am not sure how many arrays there are.  I am using a foreach loop and it
skips to last entry and i want it to subtract the first field in the last
entry from the first field in the next to last entry.  How is this done?

	      *		Web Page Designs	  *
	     / poohba@io.com  |  www.io.com/~poohba\
	     ---------------------------------------
	     \ For info about me send message with /
	      *      subject "send file help"     * 
		



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

Date: Tue, 25 May 1999 07:51:19 GMT
From: dave@dave.org.uk (Dave Cross)
Subject: Re: How do i add two values?
Message-Id: <3750564c.55888179@news.demon.co.uk>

On Tue, 25 May 1999 00:47:05 -0500, Poohba <poohba@io.com> wrote:

>I am trying to add two values from the same field but on different arrays.
>I am not sure how many arrays there are.  I am using a foreach loop and it
>skips to last entry and i want it to subtract the first field in the last
>entry from the first field in the next to last entry.  How is this done?

It's really not very clear what you're asking. Perhaps if you showed
us some code - or at least the data structures - we could help a
little more.

Dave...

--
Dave Cross <dave@dave.org.uk>
<http://www.dave.org.uk>


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

Date: Tue, 25 May 1999 11:17:58 +0300
From: Sauli Karhu <sauli.karhu@lmf.ericsson.se>
Subject: How to embed perl into Win32 applications?
Message-Id: <374A5CB6.1EBA1C09@lmf.ericsson.se>

In ActiveState's perl (build 514, I think) for win32 I can read some
info about embedding the perl interpreter into C applications (Yes, I
read perlembed). There is almost no Win32 specific info at all.

For NT/Win32 specific stuff there is a link to a FAQ page that does not
exist.

At this stage my questions is simply: What to do in order to make a
simple console application with per interpreter to work on Windows NT?
What library/ies should be linked in? lib\core contains some libraries
that I have tried without success. What other compiler options are
needed? I'm using Visual C++ 5.0.

Regards,
Sauli Karhu


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

Date: Tue, 25 May 1999 04:51:03 GMT
From: billy_collins@my-dejanews.com
Subject: Interesting question
Message-Id: <7ida7n$5fd$1@nnrp1.deja.com>

Hi people,

I was asked by one of my clients today if it is possible to prevent a
web page from being printed, or cut/pasted from. Is this possible?

Apologize for the cross posting but I definitely think that this is a
great question and the answers would be highly appreciated.

Thanks
Bill


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: 25 May 1999 09:33:05 +0200
From: mriedel@neuearbeit.de (Marko R. Riedel)
Subject: Re: Mod of large number
Message-Id: <lzd7zpli32.fsf@linux_sexi.neuearbeit.de>

sholden@pgrad.cs.usyd.edu.au (Sam Holden) writes:

> On Sun, 23 May 1999 18:37:29 -0700, Cyb=EER <cybir@echoweb.net> wrote:
> >I'm trying to take mod 3337 of 180**79 but
> >
> >$x =3D 180**79 % 3337;
> >
> >gives me 0 always, what am I doing wrong?
> =

> You don't have the following line in your code :
> =

> use Math::BigInt ':constant';
> =

> Chances are 180**79 is a little too big for the integers used by your m=
achine.
> =

> -- =

> Sam
> =

> Every human culture has good and bad points. Every computer program has=

> Eveone more bug. Even Perl.
> 	--Larry Wall

You might not want to use big integers when you can make do with small on=
es.

[IMODEXP] > imodexp.pl 5 6 100
25
[IMODEXP] > imodexp.pl 7 3 100
43
[IMODEXP] > imodexp.pl 180 79 3337
2645

#! /usr/bin/perl -w

sub imodexp {
  my ($val, $exp, $mod)=3D@_;

  return 1 if (!$exp || $val=3D=3D1);
  return $val % $mod if $exp=3D=3D1;

  my $rem=3D$exp%2;
  my $hexp=3D($exp-$rem)/2;
  my $res=3Dimodexp($val, $hexp, $mod);

  return ($res*$res*($rem>0 ? $val : 1)) % $mod;
}

MAIN:{
  print imodexp(@ARGV), "\n";
}


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

Date: Tue, 25 May 1999 07:45:09 GMT
From: dave@dave.org.uk (Dave Cross)
Subject: Re: Newbie  Perl --> HTML
Message-Id: <374e54cc.55503894@news.demon.co.uk>

On Mon, 24 May 1999 21:33:48 -0700, "Brian A. Gleber"
<bgleber1@rochester.rr.com> wrote:

>Today is my first day trying to pick up perl.  When I call my perl program
>from by Web Browser, it shows my code instead of a html document.
>
>BTW, I am running Win98 with Personal Web Server installed.  Here is my
>code, what am I doing wrong?
>
>#!C:\perl\bin\perl
>
>
>print "Content-type: text/html\n\n";
>
>
>print "<HTML><HEAD><TITLE>Hello!</TITLE></HEAD>\n";
>
>print "<BODY><H1>Hello, World!</H></BODY></HTML>\n";
>

Sounds like a web server configuration issue. You web server doesn't
know that CGI scripts should be executed rather than displayed. There
are newsgroups that deal with these issues.

Dave...

--
Dave Cross <dave@dave.org.uk>
<http://www.dave.org.uk>


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

Date: Mon, 24 May 1999 22:21:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Pigheadedness (was Re: Newbie; Perl/Tk Event models)
Message-Id: <MPG.11b3d307851cfdfd989aeb@nntp.hpl.hp.com>

In article <ebohlmanFC9nA6.KwH@netcom.com> on Tue, 25 May 1999 02:08:30 
GMT, Eric Bohlman <ebohlman@netcom.com> says...
> Collin Starkweather <collin.starkweather@colorado.edu> wrote:
> : my $update = sub {
> 
> : ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
> : $day=(Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)[$wday];
> : $month=(January,February,March,April,May,June,July,August,September,
> : 	October,November,December)[$mon];

Barewords galore!

> : $century = $year - 99 ? 20 : 19;
> : $string = sprintf <<"eop", $year, $hour, $min, $sec;
> : It is $day, $month $mday, $century%02d %02d:%02d:%02d
> : eop
> 
> : };
> 
> It is obvious that the person who wrote this code read the documentation
> for localtime(), as he's obviously learned that the year field will
> contain a value greater than 99 in the next century.  But why didn't he
> make the obvious connection and simply add 1900 to the year rather than
> trying to simulate a Fortran arithmetic IF statement?  I can only guess 
> that he had a presupposition that century-handling *had* to be more 
> complex than it really is, and dutifully wrote needlessly complicated code.

Needlessly complicated and remarkably wrong!  The years that code would 
report are 2097 2098 1999 20100 20101 .

That godforsaken code *could* be:

    $century = $year > 99 ? 20 : 19;
    $string = sprintf <<"eop", $year % 100, $hour, $min, $sec;
    It is $day, $month $mday, $century%02d %02d:%02d:%02d
    eop

And we all know what it *should* be.

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


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

Date: Tue, 25 May 1999 07:12:06 +0200
From: "Pavel Kotala" <pkotala@logis.cz>
Subject: Please, why -w file test does not work?
Message-Id: <927609337.581774@gate.logis.cz>

I asked this question several days ago. Please,  what do I wrong? In the
script on Windows NT:

while (! -w "x.txt")
{
}
open(X, ">x.txt") or die "Can not open x.txt: $!\n";

I receive "Can not open x.txt: Permission denied".

I expect, the file is locked, I simulate it by opening it by MS Word and
really it can be opened by eg. Wordpad.

So why perl pass -w (and -W) test true?

( This is the method /maybe not the best/ I want be sure, that other
program, which communicates with me by files have message completely writen.
After I have message read, I remove file.)

Thank You very much

Pavel Kotala







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

Date: Tue, 25 May 1999 04:13:25 GMT
From: amerar@unsu.com (Arthur Merar)
Subject: Printers
Message-Id: <374a2286.17862049@news.chaven.com>



Hello,

I am fairly new to Linux.  I just installed Red Hat 5.2.  My network
consists of a Windows 98 box, my Linux box and an HP LJ 4M+ network
printer.

Everything is talking fine except the Linux box and the printer.  The
printer does not seem to have an IP address.  Rather it has a network
name and hardware address......since I think Windows 98 uses the
Client for Netware Networks and stuff.

Anyhow, I'm not sure how to install the printer so I can print to it
from either Windows or Linux.  Can someone help me?

Thanks,

Please send response to e-mail.

Arthur
amerar@unsu.com



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

Date: 24 May 1999 20:31:51 PDT
From: younggs@acwilm.com
Subject: re-webifying strings for GET methods
Message-Id: <374A1A5B.4278@acwilm.com>

Hello there...

        Does anyone have a code snippet for re-webifying plain text? 
I want to create some HTML on the fly that includes links made from
database text.
For instance if

my $str="cool stuff at #E-13."  (just a stupid example, of course)

so I would need create

<a href="http://somesite.com?str=cool+stuff+at+%23E-13">

(note the translated #).  I can translate spaces to + signs easy enough,
but don't know what other characters normally get translated in GET or
POST methods. Is there a quick regular expression that will do this?

thanks

--Geoff
younggs@acwilm.com


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

Date: Tue, 25 May 1999 05:12:27 GMT
From: Otis Gospodnetic <otis@my-dejanews.com>
Subject: s/// multiple lines in file from cmd line
Message-Id: <7idbfr$692$1@nnrp1.deja.com>

Hello,

I was wondering if it is possible to replace something like this:

message_footer      <<  END
------------------------------------------------------------------------
To UNSUBSCRIBE send a message to $LIST-request@mysite.com with
UNSUBSCRIBE in the body of the message.
------------------------------------------------------------------------
END

with:
message_footer      <<  END
END

(basically remove the meat of message_footer)

 ... with a perl onliner (command line).
I tried:

perl -pi.bak -e 's/\-{60,}\n(.*)\n(.*)\-{60,}\n//' *.config

But it didn't work, of course, because of multiple lines...
Can anyone help?

Thanks,

Otis


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: 25 May 1999 01:53:35 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: s/// multiple lines in file from cmd line
Message-Id: <x7pv3pg0f4.fsf@home.sysarch.com>

>>>>> "OG" == Otis Gospodnetic <otis@my-dejanews.com> writes:

  OG> ... with a perl onliner (command line).
  OG> I tried:

  OG> perl -pi.bak -e 's/\-{60,}\n(.*)\n(.*)\-{60,}\n//' *.config

there is no need to escape - in a regex except in a char class.
since you delete all the text there is no need for the parens. they
don't do any useful grouping nor do you use their saved text.

  OG> But it didn't work, of course, because of multiple lines...

it's a decent try but as you note you can't work on multiple lines with
a plain -p loop. what you need to do is slurp in the entire file at once
and then do the s///. in this case reading in by paragraphs might work
too.

perl -0777pi.bak -e 's/\-{60,}\n(.*)\n(.*)\-{60,}\n//' *.config

the -0777 option tells perl that there is no input record separator so it
will slurp in the entire file into $_ which can then be operated upon
and written out. it makes the -p option much more powerful than the
awk/sed loops of yore.

once we have that problem solved you can tighten up your regex a
little. since your markers are the 60 - lines you could just use a
simple .+? between them along with the /s modifier to allow . to match
\n.


perl -0777pi.bak -e 's/-{60,}.+?-{60,}\n//s' *.config

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 24 May 1999 23:06:11 -0700
From: raulr@CS.Arizona.EDU (Raul R Ramirez)
Subject: String search problem
Message-Id: <7idekj$r1s@lectura.CS.Arizona.EDU>


  Silly question, but....if I have a string stored in $x,
  how can I find the POSITION of any substring???
  Let's assume that I'm looking for the first occurrance of
  a "Hello!" substring in $x ....should I use pattern matching??
  How??

  Thanks!

  ---------
  Raul R.
  raulr@lectura.cs.arizona.edu



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

Date: 25 May 1999 06:19:47 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: String search problem
Message-Id: <slrn7kkg83.kf.sholden@pgrad.cs.usyd.edu.au>

On 24 May 1999 23:06:11 -0700, Raul R Ramirez <raulr@CS.Arizona.EDU> wrote:
>
>  Silly question, but....if I have a string stored in $x,
>  how can I find the POSITION of any substring???
>  Let's assume that I'm looking for the first occurrance of
>  a "Hello!" substring in $x ....should I use pattern matching??
>  How??

index

-- 
Sam

Some of you know what the Perl slogan on Windows is, and you can say it
with me: "It's a good thing there's more than one way to do it, because
most of them don't work."  --Larry Wall


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

Date: Tue, 25 May 1999 02:39:56 GMT
From: marcel.grunauer@lovely.net (Marcel Grunauer)
Subject: Re: The docs as talking books (was Re: newbie with a "howto" question)
Message-Id: <3749f0b1.22393470@enews.newsguy.com>

On 11 May 1999 15:08:42 -0400, dha@panix.com (David H. Adler) wrote:

>On Mon, 3 May 1999 12:39:41 -0400 , Ala Qumsieh <aqumsieh@matrox.com> wrote:
>>
>>Jonathan Stowe <gellyfish@gellyfish.com> writes:
>>
>>> One area where some feedback would be useful is as to who's voice should be
>>> used - Mrs Gellyfish is dead set on that of Sir Anthony Hopkins but I think
>>> that might be national bias on her part.  Suggestions ?
>>
>>There is no question about it in my mind. The man with the Force. The
>>Darth himself.
>>
>>		"James Earl Jones"
>
>"THIS - is P5P..."

"Don't be too proud of the technological terror you've constructed.
The ability to write VBScript is insignificant next to the power of
Perl."

"I find your lack of faith disturbing."

Marcel



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

Date: Tue, 25 May 1999 04:09:08 GMT
From: mark-lists@webstylists.com (Mark Thompson)
Subject: Uploading file and e-mailing it using Perl
Message-Id: <374a214e.11497636@news.supernews.com>

Hi, 

I have a web page that has three fields, one of type text and one of type
file and a textarea field.  

What I'm trying to do is let the user upload a single file to our server and
have our server mail it out to a specified e-mail address (those are the file
and text fields).  In addition, I would like to attach a description to the
top of the e-mail message (the textarea).

I've checked the FAQ's and have found stuff on attaching a file that's
already existing on the server to an e-mail as well as stuff on uploading a
file and saving it to the server but I was wondering if anyone could give me
any resource pointers to something that would help me write the file to
e-mail without first saving it to the hard disk.

Thanks,

Mark



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

Date: Sat, 22 May 1999 18:16:31 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: using gethostbyaddr?
Message-Id: <MPG.11b0f6cd869ef9be989a46@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <slrn7keekq.2aa.cbearden@calvin.home> on 22 May 1999 23:15:41 
GMT, Chuck Bearden <cbearden@hal-pc.org> says...
 ...
>   $addr = "204.52.135.1";
>   @addr = split(/\./, $addr);
>   $addr = pack('C4', @addr);
>   #print length($addr), "\n";
>   $name = gethostbyaddr($addr, AF_INET);
> 
> gives an error:
> 
>   Argument "AF_INET" isn't numeric in ghbyaddr at ./getbyaddr line 7.
>   Use of uninitialized value at ./getbyaddr line 9.
> 
> This puzzles me, because acc. to the man pages, _Programming_Perl_, and 
> _Perl_in_a_Nutshell_, 'gethostbyaddr' takes two arguments, 'addr' and 
> 'addrtype', with the second being optional.

The documentation I have doesn't show the second argument as optional.

Had you used 'use strict;' you would have been told that AF_INET is in 
fact a bareword, whereas it is supposed to be the name of a predefined 
function that is expected to return a numeric value.  But you have not 
defined the function.

You can use the constant numeric value (2, in fact), but this is a Bad 
Thing.  A Good Thing is to include the module that defines AF_INET.

The rest of your code is correct.  But again, the module makes the code 
a bit cleaner (and handles some odd cases where the IP address doesn't 
consist of a 'dotted-quad' as your example does).

So here is the complete code:

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

my $addr = '192.151.11.32';
my $name = gethostbyaddr(inet_aton($addr), AF_INET);
print $name || $addr, "\n";

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


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

Date: Tue, 25 May 1999 06:53:28 GMT
From: ColinM <edsys@my-dejanews.com>
Subject: Writing data to: /dev/$DEV
Message-Id: <7idhd8$a2q$1@nnrp1.deja.com>

[AIX 4.2.1 && Perl 5.004_04]

We have a news-routing program written in C that wants to get it's input
from /dev/$DEV - until now $DEV = tty[1-9].

I have captured a continuous news-feed from a wire service using a perl
TCP socket & hope to feed the data to a device in /dev/pts/[1-9] in the
hope that the news-routing program will take it's input from
/dev/pts/[1-9].

I've installed IO::Pty and found that $ttyname = /dev/pts/[1-9] (where
[1-9] is the next available slave).

QUESTIONS:
==========

* Is there any means of controlling the value of $ttyname so the
news-routing program knows where to go looking for it's input (which
needs to be pre-set in it's startup file)?

* Are there likely to be sharing issues with $ttyname?

* Am I on drugs?


Any advice will be greatly appreciated.

--
ColinM


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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