[16499] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3911 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 4 06:05:34 2000

Date: Fri, 4 Aug 2000 03:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965383509-v9-i3911@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 4 Aug 2000     Volume: 9 Number: 3911

Today's topics:
    Re: cookie anyone? <rich_guy@hotmail.com>
    Re: Copying from the web: Problems with a script <jmaggard@va.mediaone.net>
    Re: delimited text to HTML table converter <jeff@vpservices.com>
    Re: Gee, thanks for all the help  :-( <jmaggard@va.mediaone.net>
    Re: Gee, thanks for all the help  :-( <bean@agentkhaki.com>
        get files from other servers <gk@bncol.com>
    Re: How to open and append to a file <godzilla@stomp.stomp.tokyo>
        LWP help please <neil@thump.org>
    Re: need help running .pl files with Apache <rich_guy@hotmail.com>
        Novice Question: Outputting an existing file <trioinfoQUITAESTO@trioinfografia.com>
    Re: perlcc[5.6.0] - Socket::PF_INET (unable to autoload <edmundtan@my-deja.com>
        Q: split on fixed length string <rich_guy@hotmail.com>
    Re: Q: split on fixed length string <jeff@vpservices.com>
    Re: remove blank character <lr@hpl.hp.com>
    Re: remove entry from file --anyone!! <rich_guy@hotmail.com>
    Re: Security (with respect to chmod) - user_create.cgi  <bean@agentkhaki.com>
    Re: Sendmail problem <rich_guy@hotmail.com>
        Uhmm... Errr... <bean@agentkhaki.com>
        Where is the best spot to flock file in this sub?? <scotnet@sympac.com.au>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 04 Aug 2000 01:49:26 -0700
From: asker <rich_guy@hotmail.com>
Subject: Re: cookie anyone?
Message-Id: <398A8396.48BA69C9@hotmail.com>

Troy Rasiah wrote:
> 
> hi all,
>         I've been wondering if this is a problem with Internet Explorer or
> me..but I'm using the following code to set a cookie that expires within 1
> second. It works fine with Netscape but IE doesn't seem to respond to it.
> For example...say i set the cookie for 10 mins at the start of the
> program..they hit on a logout button..and it sets the expire time to 1s.
> Anyone have any suggestions or comments......
> 
> my $cookie_expire='+1s' ;
> $cookie = $query->cookie(-name=>'HOTTOP',
>                          -value=>$session{_session_id},
>                          -expires=>$cookie_expire,
>                          -path=>'/',
>                          -domain=>$cookie_domain);
> 
> print $query->header(-cookie=>$cookie);
> print $query->start_html('Admin Logout');
> 
> --
> ----------------------------------------------------------------------------
> ----------------
> Troy Rasiah
> Database/Web Developer
> Vicnet
> troyr@vicnet.net.au
> ----------------------------------------------------------------------------
> ----------------

You might be better off asking this in a A: CGI News Group, or B: A
browser news Group. If this seems to be a browser issue, it's probably a
good idea to just have the cookie expire immediately upon exit or
browser shut down, rather than hoping it accepts and works with the +1s
type of thing. Try real time/dates and see if that makes any difference.


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

Date: Fri, 04 Aug 2000 07:41:56 GMT
From: Jason Maggard <jmaggard@va.mediaone.net>
Subject: Re: Copying from the web: Problems with a script
Message-Id: <398A73DE.A8F50DF4@va.mediaone.net>

Thank you for your help.  "Think binmode" had no relevancy to me.  If you
had said, "You need to use binmode. Read "perldoc -f binmode".", that
would have been helpful, and 95% of the people who read this newsgroup
would have understood it.

~Jason Maggard

One more instance of a man who says "Think water" and says he's taught you
to fish.

mccaulba@my-deja.com wrote:

> In article <398914E7.1815C92F@va.mediaone.net>,
>   Jason Maggard <jmaggard@va.mediaone.net> wrote jeopardy-style:
>
> > nobull@mail.com wrote:
> > > Files corrupted on Windoze?  Think: "binmode".
>
> > Guess you wouldn't care to elaborate??
>
> perldoc -f binmode
>
> > As for the rest, I apologize that my subject line was not up to
> > your liking, but my guess is that you still are not able to
> > identify the problem.
>
> Your guess is wrong.  I could  have told you that you need to put
> binmode(FH) after open(FH,...) but if you'd read the manual on binmode
> this would be obvious, and if I didn't succede in getting you read the
> manual on binmode then you wouldn't really have been helped.
>
> > 12 lines dedicated to a criticism of the subject line and no real
> > attempt to assist with the problem...
>
> Once more a hungry man claims that someone who tries to teach him to
> fish rather than simply giving him a fish is making no real attempt to
> assist with the problem.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.



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

Date: Fri, 04 Aug 2000 02:05:34 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: delimited text to HTML table converter
Message-Id: <398A875E.FE512132@vpservices.com>

ppopuri@hotmail.com wrote:
> 
> Does anyone know of a scipt which converts delimited text into an html
> table 

Here's a script that does that part of what you ask in 21 lines and can
be easily customized for other file types, record selections, ordering,
or table display properties.

#!perl -Tw
$|++;
use strict;
use DBI;
use CGI qw(:standard);
my $path = '/htdocs/a/databases';  # SET FILE PATH HERE
my $file = 'test_db.csv';          # SET FILE NAME HERE
my @data;
my $dbh=DBI->connect("dbi:RAM:f_dir=$path",,,{RaiseError=>1});
$dbh->func( { file_source => $file }, 'import' );
my $sth = $dbh->prepare ('SELECT * FROM table1');
$sth->execute;
while(my @row=$sth->fetchrow_array) {
    @row = map { CGI::escapeHTML($_) || '&nbsp;' } @row;
    push @data, \@row;
}
print header, start_html('My Table'), table(
    { Border => 1, Cellspacing => 0, Cellpadding => 2 },
    Tr( {bgcolor=>'#cccccc'}, th( $sth->{NAME} ),
    map Tr(td($_)), @data )
), end_html;
__END__

Enjoy!

-- 
Jeff


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

Date: Fri, 04 Aug 2000 07:53:14 GMT
From: Jason Maggard <jmaggard@va.mediaone.net>
Subject: Re: Gee, thanks for all the help  :-(
Message-Id: <398A7684.25D12E5D@va.mediaone.net>

"perl hello" should return that error.  Try perl -e print "Hello";

hello is the bareword, it is expecting an operator like print.

it is the difference between the orders:

"KIll him!"

Type, "Kill him!"


Phil Hawkins wrote:

> I have posted here twice in two days begging for help from you all and
> NO ONE seems to think my question merits anyone's attention.
>
> Nice group.  Real f****** nice group.
>
> Just so you know what I'm talking about, here's my question:
>
> ************
>
> I give up.  I bought a self-learning book on "Perl 5" and come to find
> out I must download Perl, but I go to the perl.com site and it get's
> more confusing.
>
> My host is Unix, so I tried to download the Perl 5.6.00... and it just
> froze my browser.  It appears that there are two versions?  One for NT
> and the other for
> Unix?  Huh?  I have to write two different scripts for each server
> type?  And what about the compiler?
>
> I'm brand new to this, so someone please tell me what to do to get the
> right version of Perl on my (local) machine...  I'm dazed and confused.
> The CD that came
> with the book loaded the "source code" but when I started to write my
> first scripts, it went belly up.  I got  wierd "Bare word found where
> operator expected"
> notice when all I tried to do is "% perl hello".  Christ.  Can't even
> get out of the starting block.
>
> Java was easier than this...
>
> Phil



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

Date: 04 Aug 2000 04:14:32 EDT
From: bean <bean@agentkhaki.com>
Subject: Re: Gee, thanks for all the help  :-(
Message-Id: <MPG.13f44334ad69dd07989685@news.concentric.net>

> I have posted here twice in two days begging for help from you all and
> NO ONE seems to think my question merits anyone's attention.

I could be wrong but I think I remember reading several replies to your 
question... which, I might admit, was quite confusing (as was the reply, 
but, hey, what can I say... I know very little). 

Whatever, that's my useless two cents. 

bean


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

Date: Fri, 4 Aug 2000 18:22:14 +0900
From: "Louie G. Kim" <gk@bncol.com>
Subject: get files from other servers
Message-Id: <8me1l1$cvp$1@news2.kornet.net>

Is there any way to get files from other servers?

When i am on server A, I want to get fileA from server B or
I want to display fileA at server B.

GK




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

Date: Fri, 04 Aug 2000 00:58:59 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: How to open and append to a file
Message-Id: <398A77C3.F4C28472@stomp.stomp.tokyo>

Chris Stone wrote:

(snippage here and there)

 
> Thanks for the encouragement and links.

It is my experience, a pat on the back makes
a more lasting impression than a kick on the ass.

A pat on the back is a thoughtful act.
A kick on the ass is thoughtless act.


> Truth is, I've been taking an online course at http://www.ed2go.com but 
> the pace is so slow that I only know the basics ... but now I am wishing
> I had just invested in a book (I have since ordered Learning Perl)

Most of O'Reilly books are fairly decent. Might be unfair of me as
an English instructor to critique, nevertheless, writing styles in
O'Reilly books reflect that of graduates of the Sears, Roebuck & Co.
Academy of Language Arts. Authors of O'Reilly books are not very 
good writers at all. Still, lots of good information once you get
past these poor writing styles, awkward sentences and grammar errors.
O'Reilly would be smart to include a contractual obligation to have
his books written by a professional ghost writer.
 
> I guess it was just that after looking at the FAQ I felt like a beginner,
> because I really didn't understand any of it.

Almost all Perl related FAQs, documentation and so forth, are pure gibberish.
Writers of these documents need to take a course of study in Bonehead English.

You will learn most of your programming by actually writing programs.
Trial and Error is a fabulous teacher. Use pragma hints for awhile,
if you think they will help. Stop using pragma hints as soon as possible.
Pragma hints can lead to stagnation in programming techniques and usually
lead to very mediocre programmers. Only imaginative critical thinkers
become great programmers. Pragma hints will not do this for you.
 
> I did a lot of programming on my TI-83 which is where most of my programming
> experience comes from, plus lots of HTML, a little bit of PASCAL, and even
> less of Java Script.

FORTRAN and Turbo Pascal is my background.
 
> About the script: strangely, it does not work, I got a 500 server error,
> I'll have to look back over it.

You have some syntax errors. Part of this is in those missing
quotes we both F'd up on. Hmm.. read up on "for" style loops.

Here is a bare bones script which will do what you want and,
eliminate a lot of steps along with your html document. This
script handles everything including printing your html. Only
requirement is a log file as you see in this script.

There are some user configurable needs. Provide a script name
and provide a full internal path name to your log file. Your
server can provide this internal path. Use of ../somefile is
usually not a very good idea. Sometimes works, sometimes not.
A full internal path name will always work. Look at mine for
an example.

Some notes on this. I don't expect you to use this script
but rather look it over and note different techniques. Be
sure you understand, this is an absolute bare bones script
with no security at all. It ain't pretty, form action text
boxes aren't labeled, html is incomplete and all. Error
checking for file opening is not included. You will note
many normal inclusions in a script are simply not there.

This lack of completeness has a reason.  This script is
intended to show how to develop a program with no need
for Perl 5, no need for modules and no need for pragma
hints. This is true programming, not copy and paste.

My ## COMMENTED blocks are what I think of as modules.
Each is developed and tested before others are added.
This is an example of what I discussed previously about
adding a little at a time and saving by version number.
As each module is developed and tested successfully,
you know there are no serious problems with those
modules and, in later versions, if a serious problem
develops, you know it is in the current module with
which you are working, not previously tested modules.

Scripts are dynamic. There are times a non-fatal "bug"
will appear due to a previous module. However these
bugs are almost always related to data flow or more
simply, your own logic. Components of scripts can
behave differently when new components are added.
This is what makes programming fun and, this is
something no pragma hint can catch.

So you see, pragma hints are training wheels for
syntax and typos but will never make anyone a
decent programmer. Those who adhere to pragma
hints at all times, are never and never will
be decent programmers. They don't have what
it takes; good critical logical thinking.

You may need to do a few things to get this
script up and running on your server, things
beyond providing a script name and internal
path for your log file. Permissions are one
of these things. Only you can figure out what
permissions are needed for your server. On
your log file, simply create an empty file,
give it the correct name, upload and set your
read and write permissions on. Usually a good
idea to keep log files outside your script
directory for security. However, during beta
testing, this can be dismissed to make your
work easier. 

I don't use Brenner's cgi-lib library like you
do. You will notice I do use a Brenner style
read and parse. This method requires you address
at least three basic security issues. One is
Content Length. Another is hostile html tags
and finally, meta characters. All can be very
dangerous but not needed until you are ready
to go public. Leave out security until your
basic script is ready and functioning. Get
your script up and running, all pretty and
everything, then accessorize in security.
I provided a security link previous. 

Once you have security in place, beta test
it everyway you can think of. Deliberately
abuse your script EXCEPT for those things
which will cause serious damage internally
to your server. This would not be bright.

In closing I will prompt you to look over
your script, Flexbook, my script and as
many other scripts of this nature, including
Matt's scripts, compare and incorporate 
those features you like and need. Flexbook
has some very nice error routines, very nice.

For a challenge, this script of mine will
print each time a person enters for the first
time. This can be changed with a bit of
creativity, such as adding a hidden field
to your form action, a control. 

NAME="Control" VALUE="control"....

if ($in{Control})
 { well... do the right thing here... print? }

Oh yes, before I forget, don't bother
with file locking. Are you really 
expecting millions of hits per day?
You will have better luck being struck
by lightning than having two visitors
make entries at the precise same moment.

Be realistic, keep it simple, you
will never go wrong.


As your skills mature, not so much in
programming but rather in dealing with 
Life, you will discover women are quite
talented in many ways, especially in 
employing our feminine instincts,
such as our inherent fickle nature,
to.. hmm... take care of business.

Ain't I a stinker?

Godzilla!

You're no good but I will rock you.
  http://la.znet.com/~callgirl3/nogood.mid


**


Don't forget to change the first line...



#!/usr/local/bin/perl


## SET CONTENT TYPE:

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

## READ & PARSE:

&ReadParse;

sub ReadParse
 {
  (*in) = @_ if @_;
  ($i, $key, $value);
  read (STDIN, $in, $ENV{"CONTENT_LENGTH"});
  @in = split (/&/,$in);
  foreach $i (0 .. $#in)
   {
    $in[$i] =~ s/\+/ /g;
    ($key, $value) = split (/=/,$in[$i],2);
    ($value eq "") && next;
    $key =~ s/%(..)/pack ("c",hex($1))/ge;
    $value =~ s/%(..)/pack ("c",hex($1))/ge;
## Remove comments to kill all html:
##    $value =~ s/<([^>]+)>//g;    
    $in{$key} .= "\0" if (defined($in{$key})); 
    $in{$key} .= $value;
   }
  return 1;
 }


## SET GLOBAL VARIABLES FOR FUTURE USE:

# NAME OF YOUR SCRIPT:

  $script_name = "test.cgi";

# FULL PATH NAME FOR YOUR LOG FILE:

  $log_path = "/var/ftp/home/...etc ...etc /gbentries.log"; 

# FORM ACTION VARIABLES:

  $name = $in{Name};
  $email = $in{Email};
  $homepage = $in{Homepage};
  $location = $in{Location};
  $reference = $in{Reference};
  $comments = $in{Comments};


## INSERT DESIRED TOP OF PAGE HTML HERE:

  print "<HTML><HEAD></HEAD><BODY><P><P>";


## OPEN OLD ENTRIES LOG FILE:

  open (GBENTRIES, "+<$log_path"); ## add error check


## CREATE WORKING ARRAY:

  @Gbentries = <GBENTRIES>;


## GRAB NEW ENTRY:

  $new_entry = "<P><B>Name: </B>$name</P>
                <P><B>E-mail: </B>$email</P>
                <P><B>Homepage: </B>$homepage</P>
                <P><B>Location: </B>$location</P>
                <P><B>Found page by: </B>$reference</P>
                <P><B>Comments: </B>$comments</P>";


## PUSH NEW ENTRY INTO WORKING ARRAY:

  push (@Gbentries, $new_entry);


## PRINT EACH LINE WORKING ARRAY TO LOG:

  foreach $line (@Gbentries)
   { print GBENTRIES $line; }


## CLOSE LOG BEFORE PROCEEDING:

  close (GBENTRIES); # add error check


## PRINT EACH LINE WORKING ARRAY FOR VISITOR:

  foreach $line (@Gbentries)
   { print "$line \n"; }


# INSERT DESIRED BOTTOM OF PAGE HTML HERE:

  print "<P><FORM ACTION=\"$script_name\" METHOD=\"POST\">",
        "<INPUT TYPE=\"submit\" NAME=\"Add_Comments\" VALUE=\"Add
Comments\"><P>",
        "<INPUT TYPE=\"text\" SIZE =\"30\" MAXLENGTH=\"30\" NAME=\"Name\"><br>",
        "<INPUT TYPE=\"text\" SIZE =\"30\" MAXLENGTH=\"30\"
NAME=\"Email\"><br>",
        "<INPUT TYPE=\"text\" SIZE =\"30\" MAXLENGTH=\"30\"
NAME=\"Homepage\"><br>",
        "<INPUT TYPE=\"text\" SIZE =\"30\" MAXLENGTH=\"30\"
NAME=\"Location\"><br>",
        "<INPUT TYPE=\"text\" SIZE =\"30\" MAXLENGTH=\"30\"
NAME=\"Reference\"><br>",
        "<INPUT TYPE=\"text\" SIZE =\"30\" MAXLENGTH=\"30\"
NAME=\"Comments\"><br>",
        "</FORM><P><P></BODY></HTML>";

exit;


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

Date: Fri, 04 Aug 2000 10:08:40 +0100
From: Neil <neil@thump.org>
Subject: LWP help please
Message-Id: <mIeKOWnCrvVrySZrXeOe5ifXd7OO@4ax.com>

HI

I've inhereted some LWP code which requires this package - could someone explain
what it does please ?

The script I use "uses" the package below and it seems to affect the behaviour
of an LWP useragent but I'm not sure how.


Thanks

Neil

------------- package ---------------------

# Subclass of LWP::UserAgent   ####################################

package PruTech::eosuseragent;
require LWP::UserAgent;
@PruTech::eosuseragent::ISA = ( "LWP::UserAgent");


# Overide method and alway return false.

sub redirect_ok


{
  return(0);
}

1;



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

Date: Fri, 04 Aug 2000 01:29:23 -0700
From: asker <rich_guy@hotmail.com>
Subject: Re: need help running .pl files with Apache
Message-Id: <398A7EE3.FB64208A@hotmail.com>

Christopher Thorjussen wrote:
> 
> I've got this script i want to run (and I know it works - works fine from
> console).
> 
> but I can't seem to get Apache to acknowledge .pl files. I've tried both
> from cgi-bin and from a normal folder. more or less just get the contents of
> the file displayed to me in pure ascii.
> 
> any suggestions?
> 
> -Christopher Thorjussen

You need to either configure Apache to associate the file extension .pl
with the Perl interpreter, or you need to make sure that the cgi-bin
script is a true script aliased directory. Simply because it's named
cgi-bin, doesn't mean if will be a true script aliased one. If you don't
know what I mean here, check out http://www.apache.org and your Apache
web server documentation.


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

Date: Fri, 4 Aug 2000 11:21:11 +0200
From: "Toni" <trioinfoQUITAESTO@trioinfografia.com>
Subject: Novice Question: Outputting an existing file
Message-Id: <8me1p5$jar57@SGI3651ef0.iddeo.es>

Hello!
I'm a beginner and I've this question
How can I output an existing html file from my script to the browser? I've
read about
 Location: URL
but it gives me error.
THANKS!




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

Date: Fri, 04 Aug 2000 09:47:53 GMT
From: Edmund Tan <edmundtan@my-deja.com>
Subject: Re: perlcc[5.6.0] - Socket::PF_INET (unable to autoload)
Message-Id: <8me3g8$dme$1@nnrp1.deja.com>

Hi,

I had something similar to yours, except that I managed to compile
without probs (it took a long time to finish - kind of paused for
a long while at the last compilation step).  However, I was not
able to run the executable and an error msg
'Can't locate object method "new" via package "IO::Socket::INET". '

I did not arrive here in a straightforward manner though..

I also had v5.0050 installed before upgrading to v5.6.0.

Upon the initial installation with the default options, I discovered
that my compilation wouldn't complete (after the same long pause).
There was an error msg that went:
/tmp/cca106761.o: In function 'xs_init':
/tmp/cca106761.o(.text+0x295e9): undefined reference to
'boot_DynaLoader'

This led me to think that something in the Configuration of Perl was
not correct when it was built.

I then discovered that my Linux installation didn't have the file
called 'dld.h' (which is a required file for dynamic loading on linux)
but instead had the 'dlopen.h' (which is used on SunOS, BSD).  Please
refer to
http://search.cpan.org/doc/CHIPS/perl5.004_05/ext/DynaLoader/README

Well.. the other thing was that I realised that during the failing of
compilation, it had lines which went :

Saving methods
Loaded B
Loaded IO
Loaded Fcntl
Loaded Socket

These lines were missing after I reconfigured and rebuilt Perl not to
use dynamic loading (DynaLoad ?).

Maybe you can figure something else out from here?  I currently don't
have the 'dld.h' file (according to the Configure program of Perl, I
don't, only the 'dlopen.h'), maybe if you have it, you can email it to
me?


In article <3983ED49.8BF4A3CE@solarweb.com>,
  Zach Pardos <security@solarweb.com> wrote:
> When I ran perlcc with my previous version of perl (5.0050) I recieved
> 20+ "No definition" errors. Now that I have upgraded, when I issue
> # perlcc -o getm -prog /usr/share/getm.pl
> I recieve these errors
>
> No definition for sub Socket::PF_INET
> No definition for sub Socket::PF_INET (unable to autoload)
> No definition for sub Socket::SOCK_STREAM
> No definition for sub Socket::SOCK_STREAM (unable to autoload)
>
> perlcc continues the compilation only without the nessesary Socket
> module.
> When I run the compiled binary I get an expected,  "Undefined
subroutine
> &Socket::inet_aton called".
> Suggestions on how to fix?
>
>


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


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

Date: Fri, 04 Aug 2000 01:21:27 -0700
From: asker <rich_guy@hotmail.com>
Subject: Q: split on fixed length string
Message-Id: <398A7D07.8887F02D@hotmail.com>

I'm trying to split incoming values without splitting them via any
characters like & or | or , and whatnot. This isn't anything but
trivial, but I'm just curious of how this can be done. I.e., the string
is created by concatenating the values into one string, which will
be a fixed length.

It's simple enough to do this when I only want one character, (which I
do), but how do I get more than one character using split without any
delimiters? Is this possible?

Note: the "2 to 4" and "5 to 20" would work like 2..4 and 5..20,
obviously, but in split, in this manner, it will not work in the way I
want, while still being able to pull out single characters from said
string. I don't want to have to concatenate separate variables, just to
create one that is 20 characters long in this fashion, but I don't want
to use any delimiters either.

($val1, $val2, $val3, $val4) = (split(//, $string))[0, 1, 2 to 4, 5 to
20];

I hope you get the idea and someone can tell me where to look for
information. I own all the Perl books ever made by O'Reilly, but I find
this answer nowhere, so I'm assuming this can't be done? If so, what's
an efficient way to do this, as substr seems it would be slower -- or am
I wrong?

Please post any answers or help here and don't bother trying to email,
the address isn't valid.

Thanks in advance for any assistance.


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

Date: Fri, 04 Aug 2000 02:22:18 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Q: split on fixed length string
Message-Id: <398A8B4A.FA834563@vpservices.com>

asker wrote:
> 
> ($val1, $val2, $val3, $val4) = (split(//, $string))[0, 1, 2 to 4, 5 to
> 20];

Wait, don't leave town, unpack!

As in the Perl function unpack().

For example:

    my $str     = 'abcdefghijklmnopqrstuvwxyz';
    my $pattern = 'A1 A3 A*';
    my @ary    = unpack( $pattern, $str );
    print "$_\n" for @ary;

That prints out:

    a
    bcd
    efghijklmnopqrstuvwxyz

Because the pattern said to get A1 (1 char), then A3 (3 chars), then A*
(all the rest).

-- 
Jeff


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

Date: Fri, 4 Aug 2000 00:44:03 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: remove blank character
Message-Id: <MPG.13f41414be9e796798ac35@nntp.hpl.hp.com>

In article <stsi5.69131$N4.1900458@ozemail.com.au>, troyr@vicnet.net.au 
says...
> "ChungpingLi" <cplee@bigfoot.com> wrote in message
> news:398A4477.1CE3291A@bigfoot.com...
> 
> > can anyone tell me how to remove blank character from a string
> 
> $variablename=~ s/ //g;
> 
> or
> 
> $variablename=~ s/ //x;

How odd that you should think these two modifiers will produce the same 
results!  They won't.  One solves this problem; the other doesn't.

For fastest perormance, use a special-purpose function that deals 
effectively with individual characters independent of context, as in 
this case:

  $variablename =~ tr/ //d; 

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


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

Date: Fri, 04 Aug 2000 01:33:53 -0700
From: asker <rich_guy@hotmail.com>
Subject: Re: remove entry from file --anyone!!
Message-Id: <398A7FF0.A4EBAA9B@hotmail.com>

hallian@hotmail.com wrote:
> 
> hi all,
> 
> simple question:
> 
> I need to replace the user fred from the magic file.
> File magic looks like this:
> 
> jill:nothappy:9034: gill hill
> fred:happy:9012:hill road
> nill:pop:983:jd houise
> 
> I need to remove fred from the file and move nill up so that it looks
> like this:
> 
> jill:nothappy:9034: gill hill
> nill:pop:983:jd houise
> 
> thanks
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.

Open the file, read the contents and filter out the desired content and
ignore it (I.e., s/^fred:.*//i;), then with the newly altered content
(fred's data ignored and not read in), you write the new data to said
file. Of course, it's more detailed than that, but is that what you were
looking for, the "how" in how to go about it, or the actual code? The
actual code would depend on a few different aspects and you might not
have permission to change it (of course, you might as well).


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

Date: 04 Aug 2000 04:10:51 EDT
From: bean <bean@agentkhaki.com>
Subject: Re: Security (with respect to chmod) - user_create.cgi [0/1]
Message-Id: <MPG.13f44256a78766ce989684@news.concentric.net>

> Don't see why you would want to use a system-call at all. If the files
> created has the wrong permissions, have a look at 'perldoc -f umask'.

> In any case, you should never have to use a system-call to change
> permissions on a file. Have a look at 'perldoc -f chmod' to see what
> the built-in function 'chmod' can do for you.

<grin>

Methinks I should get a newer book on Perl. Tomorrow. The book I'm using 
is called "Special Edition Using Perl for Web Programming" by David 
Harlan.

Anyway, I will have a look at those as well. I'd hate to think of how 
much other useless, clunky and taboo code I've created using that book. 

Thanks for the help. 

bean


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

Date: Fri, 04 Aug 2000 01:38:48 -0700
From: asker <rich_guy@hotmail.com>
Subject: Re: Sendmail problem
Message-Id: <398A8118.8B4AF9C0@hotmail.com>

Mitzei wrote:
> 
> I am using a script for a mailinglist. But with some mail addresses the
> following error occurs: The mails donīt arrive at the destination POP. It
> seems like the error is in the sendmail-proggy. My provider told me, that
> sendmail uses different smpt-servers (destination domain) and some/most deny
> "us".
> 
> Are there any parameters I can use to make a workaround? i.e:
> "usr/sbin/sendmail -t" (donīt know what "-t" stands for)
> 
> tia
> Alex Mitterer

This problem has nothing to do with Perl at all. If you think it's your
script and you can provide the relevant code snippet, people might be
able to help. However, again, this doesn't appear that even you think
it's a Perl issue. Perl can't know or control if emails arrive at some
remote POP server. If some email is sent and works, then it seems to be
working. It may be sendmail, or some other problem. Maybe too many
processes and some are dying off before they can send the email. If you
believe it's a problem with sendmail (believe me, it's not the -switches
there), then you can try to take a look at  http://www.sendmail.org and
see what you find there. It's probably an issue with the remote POP
server or invalid email addresses.


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

Date: 04 Aug 2000 04:33:18 EDT
From: bean <bean@agentkhaki.com>
Subject: Uhmm... Errr...
Message-Id: <MPG.13f44771a573472989686@news.concentric.net>

I have a rather (I think) unusual request. I'm looking for a Perl 
mentor. Someone who can take a look at what I've created (I'm using Perl 
mainly for CGI, but for other uses as well) and say "Well, that was 
pretty dumb... you  might want to try this..." or "Well, that was really 
dumb... why don't you read XXX and perhaps you'll get a better handle on 
it." Is this possible, or am I in Oz again. 

If anyone is interested in doing this (for free... yes, those dreaded 
words, I know) please drop me an email. Thanks. Sorry for off topic. I 
seem to be doing that a lot. Last one, I promise.

bean


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

Date: Fri, 04 Aug 2000 19:59:08 +1000
From: Scott Laughton <scotnet@sympac.com.au>
Subject: Where is the best spot to flock file in this sub??
Message-Id: <398A93EC.C5DD3B65@sympac.com.au>

Hi there,

I am wondering what is the best way to implement a file lock in the
below situation.
Say if I have a sub and it is structured as follows:
(it is a cgi script that will run on a linux box.)

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

####
#Validate input
open (FILE, "file.txt") or &throw_erra("Could not open file");
@file = <FILE>;
close (FILE);
foreach (@file) {
check if existing entry is same as input here.....
}
Do other checks on input here....
####

Update file array  @file here....

open (FILE, ">file.txt") or &throw_erra("Could not open file");
&lock_file("FILE") if $lock ==1;
print FILE @file;
close (FILE);

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

Now, with the structure of the above sub, if the file "file.txt" gets
updated
between the part where it checks the input and the part where it saves
the
updated array @file back to the "file.txt" It could still end up with
the same
entry going in twice.

So could I do the following, and lock the file when it gets opened
the first time (for reading) and just not close it (as this will unlock
the
file). And then open it again for writing while the lock is still on it
and then
close it once it has been updated (which would release the file lock)??

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

####
#Validate input
open (FILE, "file.txt") or &throw_erra("Could not open file");
&lock_file("FILE") if $lock ==1;
@file = <FILE>;

foreach (@file) {
check if existing entry is same as input here.....
}
Do other checks on input here....
####

Update file array  @file here....

open (FILE, ">file.txt") or &throw_erra("Could not open file");
print FILE @file;
close (FILE);   # Releases file lock

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

Thanks for your time....

Scott Laughton.



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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 3911
**************************************


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