[17932] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 92 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 18 18:08:28 2001

Date: Thu, 18 Jan 2001 15:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <979859111-v10-i92@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 18 Jan 2001     Volume: 10 Number: 92

Today's topics:
        [OT]: Re: FAQ 8.8:   How do I get the screen size? <mischief@velma.motion.net>
    Re: [OT]: Re: FAQ 8.8:   How do I get the screen size? <flavell@mail.cern.ch>
    Re: bug in Win32::Internet grehom@my-deja.com
    Re: chat server???? <mischief@velma.motion.net>
        deleting all files in a directory <mcdonabNO@SPAMyahoo.com>
    Re: deleting all files in a directory (Chris Fedde)
    Re: deleting all files in a directory <mcdonabNO@SPAMyahoo.com>
    Re: deleting all files in a directory rbfitzpa@my-deja.com
        email reply neurofase@my-deja.com
    Re: Event Loops and Sockets (Chris Fedde)
    Re: excel to csv tools rbfitzpa@my-deja.com
        Flock flaky over NFS how about fcntl? chuckk@monmouth.com
        flock (Brian Pontz)
    Re: HELP!! : Bi-Directional TCP Perl Sockets <dfortin@eftia.com>
    Re: How to determine current array element during a for grehom@my-deja.com
    Re: How to determine current array element during a for <mjcarman@home.com>
        how to match a space character vupt@yahoo.com
    Re: how to match a space character <juex@deja.com>
    Re: how to match a space character (Villy Kruse)
    Re: how to match a space character (Tad McClellan)
    Re: how to match a space character <jamie.oshaughnessy@ntlworld.com>
    Re: how to match a space character vupt@yahoo.com
    Re: isInNet() function (Garry Williams)
    Re: Mac Databases and MacPerl <nospam@nospam.com>
        multi-byte nagaraja@my-deja.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 18 Jan 2001 20:26:44 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: [OT]: Re: FAQ 8.8:   How do I get the screen size?
Message-Id: <t6ekc486gk5gfe@corp.supernews.com>

James Kauzlarich <nospam-abuse@[127.0.0.1]> wrote:
> AvA <a.v.a@home.nl> wrote in message news:3A65D388.E2F4B5E9@home.nl...
>> > I guess that what you are after is a script on a webserver somwhere on
>> > The internet that can send a request to another ip adress and ask that
>> > machine what size the webrowser is on the screen.
>> >

>> yes it is, silly of me to think a serverside script could do such a thing.

> I don't know how silly it is to think that it might.  Your browser gives the
> server a lot of information, such as the OS, what kind of browser you have,
> etc.  It could easily inform the server of the hight and width of the brower
> window in pixels.  It just does not.  (That I know of.)

This is getting off-topic.

If this could be done with a server-side script, it would be pretty easy to
handle in Perl. For those of you wondering why this information isn't part
of the data, the reason is that HTML is not a page description language or
a graphics layout language. It is a markup language, hence the ML in the
name. A markup language tells somethinhg how the individual elements should
appear and how they should be related to one another, not how to render the
screen. HTML, in fact, can be rendered nicely by text-only browsers or by
text-to-speech style browsers. HTTP was originally designed to service the
needs of serving HTML without using WAIS, Gopher (or its derivatives), FTP,
or some other existing transfer method. Therefore, HTTP really has no use,
in the traditional sense, for screen-size information, since it is up to
the browser how the information should be rendered. To be really accurate,
the documents/document parts in a hypertext site shouldn't really be called
pages at all, but the name has stuck.

Now, considering all the people who would like to use HTML as a page
description language and the fact that the browser type is sent back
already, perhaps the browser vendors could make the browser send the
size info at the end of the browser ID string. ;)  Perhaps a newer
version of HTTP will eventually send this information, although it
really is a bastardization of the concept behind markup languages.
If either of these things do come about, then Perl will probably be
the most popular language with which to deal with the data.

Chris

-- 
Christopher E. Stith

Programming is a tool. A tool is neither good nor evil. It is
the user who determines how it is used and to what ends.



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

Date: Thu, 18 Jan 2001 22:21:56 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: [OT]: Re: FAQ 8.8:   How do I get the screen size?
Message-Id: <Pine.LNX.4.30.0101182214170.20758-100000@lxplus003.cern.ch>

On Thu, 18 Jan 2001, Chris Stith wrote:

> Now, considering all the people who would like to use HTML as a page
> description language and the fact that the browser type is sent back
> already, perhaps the browser vendors could make the browser send the
> size info at the end of the browser ID string. ;)

I'm sure you're well aware that it's already been done...

But the real objection to your point is that the user agent string
was originally documented to be purely informational, i.e it would be
quite wrong for the server to rely on it for any functional purpose.

And indeed, as soon as data providers misguidedly started to rely on
it for functional purposes, delivering data to browser X while hurling
insults at browser Y, the more discerning users started to fool the
providers into "delivering the goods" by having browser Y masquerade
as browser X.

> If either of these things do come about, then Perl will probably be
> the most popular language with which to deal with the data.

Hey, that was one way of dragging the thread kicking and screaming
back on topic for the group!

all the best



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

Date: Thu, 18 Jan 2001 20:39:24 GMT
From: grehom@my-deja.com
Subject: Re: bug in Win32::Internet
Message-Id: <947k9q$qks$1@nnrp1.deja.com>

I have found that the routine here works perfectly on my Win98 machine
but not on the Win NT machine accessing the same SCO Unix server and
using the same (latest) version of Activestate Perl installation.  Can
I apologize and say that I produced the results below on the Win98 and
I know now that they are correct; however running this on the Win NT
machine at work does show the problem where intermitently the year on
files created last year is showing as this year - you see dates like 31-
JUN-2001 etc.

Am I addressing this to the wrong forum?  How can I contact the
writers/maintainers of the FTP routines within the Win32::Internet
module?  This may not be a Perl problem when I run the test program in
the debugger I can't step down into the routine that returns the bad
values.

In article <941vgd$uoi$1@nnrp1.deja.com>,
  grehom@my-deja.com wrote:
> I am finding incorrect years (this year on files from last year) using
> this test program:
> #!perl -w
>     use Win32::Internet;
>     my $INET = new Win32::Internet();
>     $INET->FTP($FTP, "server_name", "user_name", "password");
>     $FTP->Cd("/user/cwintops/site/cis/design_docs");
>     my @files = $FTP->List("*.*", 3);
>     foreach my $file (@files) {
>         print $file->{'name'}, " "
>             , $file->{'size'}, " "
>             , $file->{'mtime'}, "\n";
>     }
> I am running on Windows NT using latest release of Activestate's Perl
> (build 623) - the module above is built into the release - could
someone
> try it on their machine - thanks.


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 18 Jan 2001 20:54:04 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: chat server????
Message-Id: <t6elvcps6d91b6@corp.supernews.com>

jslutzky@my-deja.com wrote:
> I'm new to this group, but not to Perl.  I'm running apache on a RH6.2
> server and looking to beef up our companies intranet.

> Does anyone know of a nice (FREE) chat server, that has a client that
> is os independent?????

http://chat.yahoo.com ;)

Seriously, though, your best bet for a platform-independent chat client
is a client written in Java. Perl runs on most platforms, but is not
installed by default on most platforms. Most do, however, have a
Java-capable browser already installed.

The best fix overall is to get Apple and Microsoft to bundle Perl.
The most reasonable fix is probably to go ahead and use a Java-based
client. You could always use an HTML and CGI chat client, but that
either requires a freequent refresh or requires the reader to click
on an update button every so often.

> I have been scouring the net and have found a few, but want to get some
> info from anyone that might have been in the same position that i'm in
> right now.

There are bunches of IRC clients in Java and a few telnet clients
in Java, so you could make your backend yourself without a pre-made
chat server or requiring a certain level of functionality in the
vendor's telnet client. You also wouldn't have go do any machine-by-
machine installations of the client, since the browser can take care
of that with a Java client. Of course, this isn't a huge advantage
on 95/98, but under NT or 2000 you can let a user download and run
an applet without letting them download and install and application.
Since the Perl interpreter is the application as far as the OS is
concerned, if you did install Perl (ActiveState or maybe MacPerl on
your desktops most likely), your users could download and run most
any Perl script they like (although the access allowed the Perl
script is still determined by the user's access rights).

If I was running a bunch of custom apps on the desktops here, I'd
install ActiveState's ActivePerl on all the desktops and write Perl
for them. However, we run most everything CGI instead of client-server,
because we don't need anything like chat server that requires real-time
interaction.

Chris

-- 
Christopher E. Stith

Parking for people we like only. All other vehicles will be vandalized.



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

Date: Thu, 18 Jan 2001 12:48:55 -0800
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: deleting all files in a directory
Message-Id: <XFI96.22$Ub2.55941@news.pacbell.net>


Hi. I am trying to figure out why the following bit of code won't work...

I get the error...

could not unlink './xilinx_v_altera/*' No such file or directory

What I'm trying to do is check for the existence of a directory. If it is
present, I want to delete all the files within it. If it is not present, I
want to create it.

In the case that generates the error above the directory does exist. And
it's filled with .xml files.

Any ideas on what's wrong? Better ways of doing it?

Brian

<CODE>
 # check if this case's xml directory has already been created. if so,
 # delete it's contents. if not, create the directory.
 #
 if (-d $casename) {
  my @files = glob("./$casename/*");
  unlink "./$casename/@files" or die "could not unlink './$casename/*'
$!\n";
 } else {
  mkdir $casename, 0777 || die "can't create directory $casename: $!\n";
 }
</CODE>




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

Date: Thu, 18 Jan 2001 21:49:09 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: deleting all files in a directory
Message-Id: <pxJ96.1090$B9.193146368@news.frii.net>

In article <XFI96.22$Ub2.55941@news.pacbell.net>,
Brian McDonald <mcdonabNO@SPAMyahoo.com> wrote:
>
>Hi. I am trying to figure out why the following bit of code won't work...
>
><CODE>
> # check if this case's xml directory has already been created. if so,
> # delete it's contents. if not, create the directory.
> #
> if (-d $casename) {
>  my @files = glob("./$casename/*");
>  unlink "./$casename/@files" or die "could not unlink './$casename/*'
>$!\n";
> } else {
>  mkdir $casename, 0777 || die "can't create directory $casename: $!\n";
> }
></CODE>
>

glob will include the path component.  

    unlink @files

Might be a better choice here.

chris
-- 
    This space intentionally left blank


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

Date: Thu, 18 Jan 2001 14:04:46 -0800
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: deleting all files in a directory
Message-Id: <2NJ96.33$Ub2.71960@news.pacbell.net>


"Chris Fedde" <cfedde@fedde.littleton.co.us> wrote in message
news:pxJ96.1090$B9.193146368@news.frii.net...
> In article <XFI96.22$Ub2.55941@news.pacbell.net>,
> Brian McDonald <mcdonabNO@SPAMyahoo.com> wrote:
> >
>
> glob will include the path component.
>
>     unlink @files
>
> Might be a better choice here.
>
> chris

that did the trick. danke.

brian




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

Date: Thu, 18 Jan 2001 22:03:02 GMT
From: rbfitzpa@my-deja.com
Subject: Re: deleting all files in a directory
Message-Id: <947p6f$vao$1@nnrp1.deja.com>

You might want to break up your code, I'm not sure if the unlink command
can handle an array, try:

foreach $file (@files)
{
     unlink "./$casename/$file"
}

In article <XFI96.22$Ub2.55941@news.pacbell.net>,
  "Brian McDonald" <mcdonabNO@SPAMyahoo.com> wrote:
>
> Hi. I am trying to figure out why the following bit of code won't
work...
>
> I get the error...
>
> could not unlink './xilinx_v_altera/*' No such file or directory
>
> What I'm trying to do is check for the existence of a directory. If it
is
> present, I want to delete all the files within it. If it is not
present, I
> want to create it.
>
> In the case that generates the error above the directory does exist.
And
> it's filled with .xml files.
>
> Any ideas on what's wrong? Better ways of doing it?
>
> Brian
>
> <CODE>
>  # check if this case's xml directory has already been created. if so,
>  # delete it's contents. if not, create the directory.
>  #
>  if (-d $casename) {
>   my @files = glob("./$casename/*");
>   unlink "./$casename/@files" or die "could not unlink './$casename/*'
> $!\n";
>  } else {
>   mkdir $casename, 0777 || die "can't create directory $casename:
$!\n";
>  }
> </CODE>
>
>


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 18 Jan 2001 21:18:22 GMT
From: neurofase@my-deja.com
Subject: email reply
Message-Id: <947mil$sra$1@nnrp1.deja.com>

I am perl to convert a form on the internet into an email but i was
looking to make it that the email came from the email addy that was
entered by the user so it was easier to reply. The bit that is getting
me is i have to use the \ in the email. Can anyone help?


 use Net::SMTP;

        $smtp = Net::SMTP->new('EXCHANGE'); # connect to an SMTP server
        $smtp->mail( 'website@ozarks.edu' );     # use the sender's
address here
        $smtp->to('lgarriso@email.com', 'webmaster@email.com');
# recipient's address
        $smtp->data();                      # Start the mail

        # Send the header.
        $smtp->datasend("To: lgarriso\@email.com,
webmaster\@ozarks.edu\n");
        $smtp->datasend("From: website\@email.com\n");
        $smtp->datasend("Subject: Satisfaction Survey of Maintance
Request (from Web Site)\n");
        $smtp->datasend("\n");

# Send the body.
$smtp->datasend("Time Sent(Local) $now\n");
$smtp->datasend("\n");
$smtp->datasend("Survey on Work Requested\n");
$smtp->datasend("E-mail: $input{'email'}\n");


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 18 Jan 2001 21:44:09 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Event Loops and Sockets
Message-Id: <JsJ96.1089$B9.192882688@news.frii.net>

In article <947351$9mg$1@nnrp1.deja.com>,  <kgenus@earthlink.net> wrote:
>I need to write an engine to listen to a port and
>respond to events that I send it from a client.  I
>am wondering what additional ways I can do this
>instead of using the IO::Socket API (which I need
>to know more about).  I have all of my engine
>completed, but the code is piece mill and there
>just has to be a better way to write it ... or
>some EventLoop based modules already written. Any
>help would be great.
>

Several event handler classes are available on CPAN  There is also IO::Select.
Hope that you find someting that works for you.

chris

-- 
    This space intentionally left blank


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

Date: Thu, 18 Jan 2001 20:17:59 GMT
From: rbfitzpa@my-deja.com
Subject: Re: excel to csv tools
Message-Id: <947j1b$peg$1@nnrp1.deja.com>

Thank you,

I found win32::ole and I think it will do exactly what I want.
Unfortunatley I'm having a hard time installing it, it complains about a
missing delimiter in the makefile when I try to install it. ( I checked
and it's not installed on my system).

The Readme indicates I need C++ installed to compile it, which I don't
have anyway but when I tried installing it on another system it also
complained that it was missing windows.h and another file.

I'm running on a solaris 2.6 machine, can I get a binary copy
of win32::ole anywhere?



In article <3a670936.7657661@News.CIS.DFN.DE>,
  jmcnamara@cpan.org (John McNamara) wrote:
> Ar Wed, 17 Jan 2001 19:49:44 GMT, do schriobh rbfitzpa@my-deja.com:
> >I've seen some perl tools in the past which convert excel
spreadsheets
> >to csv delimited text files, does anyone know where I can find them
and
> >or any documentation?
>
> I don't think that there is any tool that does this directly. Have a
> look at Win32::OLE, Spreadsheet::ParseExcel or DBI with DBD::ADO or
> DBD::ODBC.
>
> John McNamara
> --
> "Something tells me we aren't programming in Pascal anymore, Toto."
>
>


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 18 Jan 2001 21:21:20 GMT
From: chuckk@monmouth.com
Subject: Flock flaky over NFS how about fcntl?
Message-Id: <947mo6$suu$1@nnrp1.deja.com>



All,

I posted a message a while back about flock being flaky over NFS
when multiple programs on multiple machines try to flock the same file
on a NFS mounted device.

***I forgot to ask an obvious question....***

Does fcntl suffer from the same problem?
Any people have experience trying this?

Thanks,
chuck



Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 18 Jan 2001 21:41:47 GMT
From: pontz@NO_SPAM.channel1.com (Brian Pontz)
Subject: flock
Message-Id: <3a676305.92692695@news.e-dialog.com>

I came across the below code on the web. My question is
why do you need the seek(MBOX, 0, 2) ? It's my understanding that (on
unix ) when you open a file for appending, you always write to the end
of the file. It wouldnt matter if another program wrote to the end
while you where waiting for the lock. Am I correct on this?

Thanks
Brian Pontz

    sub lock {
        flock(MBOX,LOCK_EX);
        # and, in case someone appended
        # while we were waiting...
        seek(MBOX, 0, 2);
    }


    sub unlock {
        flock(MBOX,LOCK_UN);
    }


    open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
            or die "Can't open mailbox: $!";


    lock();
    print MBOX $msg,"\n\n";
    unlock();



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

Date: Thu, 18 Jan 2001 16:31:13 -0500
From: "Dennis Fortin" <dfortin@eftia.com>
Subject: Re: HELP!! : Bi-Directional TCP Perl Sockets
Message-Id: <7hJ96.121337$Z2.1460022@nnrp1.uunet.ca>

Good day,

Thank you for your input, it helped me solve a few of my problems, However,
I was wondering if there is there any way I can do this without shutting
down part of the socket connection? I understand that
    while($line = <$new_sock>) {
        $request .= $line;
    }
blocks until there is an EOF read in, or there is no more connection. So,
can I shove an EOF down the socket, thereby stopping the read, but keeping
the socket connection open?

Any help that can provided will be greatly appreciated.

Thanks,
D Fortin


<nobull@mail.com> wrote in message news:u9ae8og3kf.fsf@wcl-l.bham.ac.uk...
> "Dennis Fortin" <dfortin@eftia.com> writes:
>
> > I have a question involving bi-directional communication using TCP
sockets
> > in Perl.
>
> Actually your choice of Perl as the implementation language is
> irrelvant.  This is a language-independant socket newbie mistake.
>
> >         while($line = <$new_sock>) {
> >             $request .= $line;
> >         }
>
> The above will block until an EOF condtion occurs reading $new_sock.
>
> Since $new_sock is a socket this means it blocks until the thing at
> the other end of the socket closes the socket or does a shutdown() to
> say that it's finished writing.
>
> > In any case, I'm looking for some insite to my problem. Maybe there's
> > something that I missed, or am not looking at.
>
> shutdown()
>
> --
>      \\   ( )
>   .  _\\__[oo
>  .__/  \\ /\@
>  .  l___\\
>   # ll  l\\
>  ###LL  LL\\




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

Date: Thu, 18 Jan 2001 19:37:37 GMT
From: grehom@my-deja.com
Subject: Re: How to determine current array element during a for loop
Message-Id: <947gm0$n2h$1@nnrp1.deja.com>

#!perl -w
    use strict;
    my @grouplogins = ();

    $grouplogins[1] = 12;
    $grouplogins[2] = 86;
    $grouplogins[4] = 3;
    $grouplogins[8] = 34;
    $grouplogins[9] = 104;

    my $i = 0;
    foreach my $line(@grouplogins) {
        print "Logins for group $i: $line\n" if $line;
        $i++;
    }

or am I missing the point?

In article <heF96.1322$ed.565345@nntp2.onemain.com>,
  "Chris Rogers" <xchris.rogers@xvifanusa.com> wrote:
> I want to output the contents of an array element by element.  I also
need
> to output the current element's name during a for loop but don't know
how to
> access that.  I searched the camel book and can't find the answer.
Here's a
> small example describe what I'm trying to do.
>
> Let's say that:
> $grouplogins[1] = 12
> $grouplogins[2] = 86
> $grouplogins[4] = 3
> $grouplogins[8] = 34
> $grouplogins[9] = 104
>
> foreach $line(@grouplogins)
> {
>     print "Logins for group $#grouplogins: $line\n";
> }
>
> Originally, I thought that the $#grouplogins would give me the current
> element in the for loop but now I know that it returns the identifier
for
> the last element in the array regardless of the loop.  How do I
determine
> the current element of the array during this loop?
>
>


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 18 Jan 2001 11:13:28 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: How to determine current array element during a for loop
Message-Id: <3A672438.63B05D84@home.com>

Chris Rogers wrote:
> 
> I want to output the contents of an array element by element.  
> I also need to output the current element's name during a for 
> loop but don't know how to access that.  I searched the camel 
> book and can't find the answer.  Here's a small example 
> describe what I'm trying to do.
> 
> Let's say that:
> $grouplogins[1] = 12
> $grouplogins[2] = 86
> $grouplogins[4] = 3
> $grouplogins[8] = 34
> $grouplogins[9] = 104

What about indices 0, 3, and 5 - 7?
 
> foreach $line(@grouplogins)
> {
>     print "Logins for group $#grouplogins: $line\n";
> }
> 
> Originally, I thought that the $#grouplogins would give me the 
> current element in the for loop but now I know that it returns 
> the identifier for the last element in the array regardless of
> the loop.  How do I determine the current element of the array 
> during this loop?

You iterate over the array by index, not by value:

foreach my $i (0 .. $#grouplogins) {
    print "Logins for group $i: $grouplogins[$i]\n";
}

But this will misbehave if you really only have the array elements shown
above, because some elements are undefined. Perl doesn't support sparse
arrays. If you really only want data for groups 1,2,4,8,9 you should
probably use a hash instead of an array:

my %grouplogins = (
    1 => 12,
    2 => 86,
    4 => 3,
    8 => 34,
    9 => 104,
);

foreach my $group (sort {$a <=> $b} keys %grouplogins) {
    print "Logins for group $group: $grouplogins{$group}\n";
}

If you *must* use an array (because, e.g. you don't control the data
format) you can skip past the undefined elements:

foreach my $i (0 .. $#grouplogins) {
    next unless defined $grouplogins[$i];
    print "Logins for group $i: $grouplogins[$i]\n";
}

-mjc


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

Date: Thu, 18 Jan 2001 21:20:52 GMT
From: vupt@yahoo.com
Subject: how to match a space character
Message-Id: <947mna$suk$1@nnrp1.deja.com>

Hi,

Just a quick easy question that is driving me nuts. How do I match a
blank space?

For example if $string="hhh hhh";
I want the below snippet to pring "hhhhhh" {I want blank to be omitted}
But everytime I run the code, "hhh hhh" is printed which suggests to me
that the blank space is being matched when I don't want it to.

foreach($string){
   if($_ ne " " ){
     print "$_";
    }
}


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 18 Jan 2001 13:52:12 -0800
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: how to match a space character
Message-Id: <3a67658c$1@news.microsoft.com>

<vupt@yahoo.com> wrote in message news:947mna$suk$1@nnrp1.deja.com...
> For example if $string="hhh hhh";
> I want the below snippet to pring "hhhhhh" {I want blank to be omitted}
> But everytime I run the code, "hhh hhh" is printed which suggests to me
> that the blank space is being matched when I don't want it to.
>
> foreach($string){
>    if($_ ne " " ){
>      print "$_";
>     }
> }

Well, assuming $string contains the text "hhh hhh".
This text is certainly not equal to " " (i.e. the space character).
And therefore the condition evaluates to true and the text is printed.

Maybe you are confusing string equal/not equal with pattern matching?

jue




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

Date: 18 Jan 2001 22:19:24 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: how to match a space character
Message-Id: <slrn96eqvc.hhc.vek@pharmnl.ohout.pharmapartners.nl>

On Thu, 18 Jan 2001 13:52:12 -0800, Jürgen Exner <juex@deja.com> wrote:
><vupt@yahoo.com> wrote in message news:947mna$suk$1@nnrp1.deja.com...
>> For example if $string="hhh hhh";
>> I want the below snippet to pring "hhhhhh" {I want blank to be omitted}
>> But everytime I run the code, "hhh hhh" is printed which suggests to me
>> that the blank space is being matched when I don't want it to.
>>
>> foreach($string){
>>    if($_ ne " " ){
>>      print "$_";
>>     }
>> }
>
>Well, assuming $string contains the text "hhh hhh".
>This text is certainly not equal to " " (i.e. the space character).
>And therefore the condition evaluates to true and the text is printed.
>
>Maybe you are confusing string equal/not equal with pattern matching?
>
>jue
>
>


#!perl -w
my $string = "hhhh hhhhh";
if ( $string =~ m/ / ) { print "Space found in \"$string\"\n"; }
__END__

Space found in "hhhh hhhhh"




-- 
Villy


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

Date: Thu, 18 Jan 2001 22:24:35 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how to match a space character
Message-Id: <slrn96ek5p.5jn.tadmc@tadmc26.august.net>

vupt@yahoo.com <vupt@yahoo.com> wrote:
>
>Just a quick easy question that is driving me nuts. How do I match a
>blank space?


You match a space character with

   / /     (a space character in a pattern match)

You test to see if two strings are equal using the "eq" operator.

Above you seem to be asking for one of those, but below
you seem to be asking for the other one.


>For example if $string="hhh hhh";
>I want the below snippet to pring "hhhhhh" {I want blank to be omitted}
>But everytime I run the code, "hhh hhh" is printed which suggests to me
>that the blank space is being matched when I don't want it to.
>
>foreach($string){


How many times will this loop iterate given your assignment to 
$string above?

You are looping over strings. How many strings are there? One.
The loop executes one time. The value of $_ during the only
iteration will be the 7 character string that you assigned.

>   if($_ ne " " ){

A 7 character string cannot possibly be equal to a 1 character string.


You have a string, but you want to loop over _characters_. You
need to devise a way of separating out the characters from
the string you have:

   foreach my $char ( split //, $string ) {
      # body as you already had


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


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

Date: Thu, 18 Jan 2001 22:35:36 +0000
From: Jamie O'Shaughnessy <jamie.oshaughnessy@ntlworld.com>
Subject: Re: how to match a space character
Message-Id: <4ire6t8pt28g1vo12ck54nu4b8s227uvd9@4ax.com>

On Thu, 18 Jan 2001 21:20:52 GMT, vupt@yahoo.com wrote:

>Just a quick easy question that is driving me nuts. How do I match a
>blank space?

If the variable is a space char, e.g.
my $var = ' ';
if($var eq ' ') {
  # works!
}

>For example if $string="hhh hhh";

But if you want to detect *within* a string, e.g.

my $var = 'hhh hhh';
if($var =~ / /) {
  # works
}

This is called a pattern match, and it's *very* powerful. Read up
about them. Or if you want to match whitespace, rather than just a
space char:

my $var = 'hhh hhh';
if($var =~ /\s/) {
  # works
}

>I want the below snippet to pring "hhhhhh" {I want blank to be omitted}
>But everytime I run the code, "hhh hhh" is printed which suggests to me
>that the blank space is being matched when I don't want it to.
>
>foreach($string){
>   if($_ ne " " ){
>     print "$_";
>    }
>}

You're basically wrong with the "foreach($string)" bit. It doesn't
iterator over each character of the string. The ($string) you're
passing in is a list of 1 element, which is $string. So the loop is
only executed once with the $_ value equal to $string. So can you
understand why it's not working?

If you just want to print out the string without the spaces in it:

my $var = 'hhh hhh';
$var =~ s/\s//g;
print $var;

This is a substitution or search and replace. It replaces all
whitespace in the $var by nothing. The 'g' means globally, i.e. every
match, not just the first.

Jamie



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

Date: Thu, 18 Jan 2001 22:45:48 GMT
From: vupt@yahoo.com
Subject: Re: how to match a space character
Message-Id: <947rmo$20v$1@nnrp1.deja.com>

Hi,

Thanks for pointing my error out. I thought foreach($string) would
iterate over each character in the string but after reading your post,
I did a test and found out that it does not do that.

My original goal was that I needed to determine if a string was made up
of blanks or not. For example
"aaaaa" not empty, "   " empty.

Here is a function that I wrote that seems to do what I want. I'm sure
there must be a better way to determine if a string is made up of
blanks. But here is a function that I came up with that seems to do
what I want.
sub isEmptyString{
  ($string)=@_;
  $_ = $string;
  $length = tr/a-zA-Z/0-9/;
  if ($length >0){
    print "not empty";
    return 0;
  }else {
    print "empty";
    return 1;
  }
}
In article <3a67658c$1@news.microsoft.com>,
  "Jürgen Exner" <juex@deja.com> wrote:
> <vupt@yahoo.com> wrote in message news:947mna$suk$1@nnrp1.deja.com...
> > For example if $string="hhh hhh";
> > I want the below snippet to pring "hhhhhh" {I want blank to be
omitted}
> > But everytime I run the code, "hhh hhh" is printed which suggests
to me
> > that the blank space is being matched when I don't want it to.
> >
> > foreach($string){
> >    if($_ ne " " ){
> >      print "$_";
> >     }
> > }
>
> Well, assuming $string contains the text "hhh hhh".
> This text is certainly not equal to " " (i.e. the space character).
> And therefore the condition evaluates to true and the text is printed.
>
> Maybe you are confusing string equal/not equal with pattern matching?
>
> jue
>
>


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 18 Jan 2001 19:58:30 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: isInNet() function
Message-Id: <GVH96.337$032.12263@eagle.america.net>

On Thu, 18 Jan 2001 17:54:22 GMT, snval0@my-deja.com <snval0@my-deja.com> wrote:
>Guys,
>
>Thanks for all your help.
>It's working right now!
>And yes I know that the IP address looked a bit strange, but I didn't
>want to put the real one in :-)

The IP address looked fine; it was the network address/mask that made
no sense.  

>Thanks again!

You're welcome.  

-- 
Garry Williams


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

Date: 18 Jan 2001 20:56:10 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: Mac Databases and MacPerl
Message-Id: <947l9a$j4j$0@216.155.33.69>

In article <3a665f8c$0$15489$7f31c96c@news01.syd.optusnet.com.au>, 
"Jeffrey Grace" <gracenews@optusnet.com.au> wrote:

 | NB: I've described behaviour of MacPERL when I was using it 12 
 | months ago, I no longer develop on a mac, and there might have been 
 | a newer version that acts differently, best to check the MacPERL web 
 | site to check.

the current 520r4 (5.004) MacPerl still functions this way, although a 
port to a more recent version of Perl is currently underway. (yay!) 

and of course under OS X, this problem goes away, as Perl is 'native' 
there.

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Thu, 18 Jan 2001 21:28:04 GMT
From: nagaraja@my-deja.com
Subject: multi-byte
Message-Id: <947n4o$tdl$1@nnrp1.deja.com>

Are there any problems or issues in handling unicode and international
character sets in Perl 5.6?

Thanks,

Chandra


Sent via Deja.com
http://www.deja.com/


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

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


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