[23070] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5291 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 30 06:05:59 2003

Date: Wed, 30 Jul 2003 03:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 30 Jul 2003     Volume: 10 Number: 5291

Today's topics:
    Re: Anyone build the Berkeley DBXML library for AS and  <kevin@vaildc.net>
    Re: Calculate directorysize from a list? (Math55)
    Re: Can't load DBI module <r_reidy@comcast.net>
        Discrepancy in Time? (Jason Quek)
    Re: failed /g match on empty string does not reset pos( <dbo@xbn.nl>
    Re: hash problems <bart.lateur@pandora.be>
    Re: help with file dialog <mgarrish@rogers.com>
    Re: Help with parsing text file (Tad McClellan)
    Re: How do you Call a Perl subroutine with a variable n <noreply@gunnar.cc>
    Re: How do you Call a Perl subroutine with a variable n <noreply@gunnar.cc>
    Re: How do you Call a Perl subroutine with a variable n <noreply@gunnar.cc>
    Re: How do you Call a Perl subroutine with a variable n <uri@stemsystems.com>
    Re: How do you Call a Perl subroutine with a variable n <uri@stemsystems.com>
    Re: New to Perl <g4rry_sh0rt@zw4llet.com>
    Re: Perl - how to compute totals via hash request (Tad McClellan)
    Re: remote readdir() <mgjv@tradingpost.com.au>
    Re: remote readdir() <g4rry_sh0rt@zw4llet.com>
        split alternative using regexp? (Greg)
    Re: split alternative using regexp? <thens@nospam.com>
    Re: split alternative using regexp? <tassilo.parseval@rwth-aachen.de>
    Re: Win32 Ole <bart.lateur@pandora.be>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 29 Jul 2003 21:54:55 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Anyone build the Berkeley DBXML library for AS and Windows?
Message-Id: <kevin-FCCE6C.21545429072003@vienna7.his.com>

In article <1001ff04.0307290651.a57c8b4@posting.google.com>,
 bobx@linuxmail.org (Bob) wrote:

> I am on Windows and do not have a compiler. Had anyone compiled the
> Berkeley DBXML library for Windows? I would like to try out DBXML.

The library itself is available as a binary download from SleepyCat.  
Dunno about using it with Perl, though.
-- 
Kevin Michael Vail | Dogbert: That's circular reasoning.
kevin@vaildc.net   | Dilbert: I prefer to think of it as no loose ends.
http://www.vaildc.net/kevin/


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

Date: 30 Jul 2003 00:42:19 -0700
From: magelord@t-online.de (Math55)
Subject: Re: Calculate directorysize from a list?
Message-Id: <a2b8188a.0307292342.7261b061@posting.google.com>

"David K. Wall" <usenet@dwall.fastmail.fm> wrote in message news:<Xns93C7B723587DAdkwwashere@216.168.3.30>...
> Math55 <magelord@t-online.de> wrote:
> 
> > how must i change the code so it works with this implementation?
> > thanks :)
> 
> Pay me lots of money and I'll do it for you.  Otherwise, spend a few 
> minutes reading the code.  It's not exactly complicated, and besides it 
> may not even do what you want.  If you understand Greg Bacon's code[1] 
> then what I posted should present no problem.
> 
> (I didn't notice the thread from several weeks ago about this problem 
> until after I had posted.)
> 
> [1] Message-ID: <vg8iancknatk3c@corp.supernews.com>


ok, i think i got it now. there is only one problem left. here is the cdoe:


---
use strict;
use warnings;
use File::Basename;
 
my $path1 = '/tmp/FILTEREDLIST.mpf';
  
print calc("/tmp/FSHOME/icons"); 
 
 
sub calc{ 
 
	my $args = $_[0];
	
	open FH, "< $path1" or die $!;
	
	my %dir_total;
	my $path;
	while (<FH>) {
     chomp;
     next unless /^(\S+)\s+(\S+.*)$/;  # skip invalid input
     my ($size, $filename) = ($1, $2);
     my $bytes = toBytes($size);
     
     $path = dirname $filename;
     while ($path) {
         $dir_total{$path} += $bytes;
         last if $path eq '/';   # stop when we reach the root
         $path = dirname $path;
     }
 }
 
	#use Data::Dumper;/FSHOME
	#print Dumper \%dir_total; # I didn't want to write an output routine
	#for my $file ( sort keys %dir_total ){
    return ($dir_total{$args});
    #return (%dir_total);
    
    #print "total:  $dir_total{$args}\n";
	#}
} 


sub toBytes {
	my $size = shift;
   if ( $size =~ /^(\d+)(.?)$/ ) {
    	return $1                if $2 eq '';
        return $1*1024           if $2 eq 'k';
        return $1*1024*1024      if $2 eq 'M';
        return $1*1024*1024*1024 if $2 eq 'G';
     }
     warn "Unexpected input to toBytes: '$size'";
     return 0;   # may not be what you want
}

---

FILTEREDLIST.mpf looks like that:

152k	/tmp/FSHOME/icons
8.0k	/tmp/FSHOME/icons/X.gif
4.0k	/tmp/FSHOME/icons/agent.gif
4.0k	/tmp/FSHOME/icons/cdimage.gif
4.0k	/tmp/FSHOME/icons/cdwriter_unmount.gif
4.0k	/tmp/FSHOME/icons/connect_creating.gif
8.0k	/tmp/FSHOME/icons/debian.gif
4.0k	/tmp/FSHOME/icons/exit.gif
4.0k	/tmp/FSHOME/icons/filefind.gif
4.0k	/tmp/FSHOME/icons/fileopen.gif
4.0k	/tmp/FSHOME/icons/folder_yellow_open.gif
4.0k	/tmp/FSHOME/icons/gohome.gif
4.0k	/tmp/FSHOME/icons/help.gif
4.0k	/tmp/FSHOME/icons/idea.gif
4.0k	/tmp/FSHOME/icons/info.gif
4.0k	/tmp/FSHOME/icons/kedit.gif
4.0k	/tmp/FSHOME/icons/koncd.gif
4.0k	/tmp/FSHOME/icons/kscreensaver.gif
4.0k	/tmp/FSHOME/icons/ktip.gif
4.0k	/tmp/FSHOME/icons/mandrake.gif
4.0k	/tmp/FSHOME/icons/personal.gif
4.0k	/tmp/FSHOME/icons/pfaster.gif
4.0k	/tmp/FSHOME/icons/ping.gif
4.0k	/tmp/FSHOME/icons/redfaction.gif
8.0k	/tmp/FSHOME/icons/redhat.gif
4.0k	/tmp/FSHOME/icons/stop.gif
8.0k	/tmp/FSHOME/icons/suse.gif
4.0k	/tmp/FSHOME/icons/tar.gif
4.0k	/tmp/FSHOME/icons/tgz.gif
8.0k	/tmp/FSHOME/icons/tux.gif
4.0k	/tmp/FSHOME/icons/txt.gif
4.0k	/tmp/FSHOME/icons/view_text.gif
4.0k	/tmp/FSHOME/icons/zip.gif

when i call the method like i did in the code above i get 0 as return value, why?

THANKS FOR YOUR EFFORTS:)


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

Date: Tue, 29 Jul 2003 19:04:19 -0600
From: Ron Reidy <r_reidy@comcast.net>
Subject: Re: Can't load DBI module
Message-Id: <3F271993.9030109@comcast.net>

Check permissions of the DBI.pm file.

RC wrote:
> I used REdhat Linux 7.2 for PostgreSQL 7.1.3
> database
> 
> I installed DBI and DBD modules without problem.
> But when I test it by
> 
> PER_DL_DEBUG=255
> perl -e 'use DBI;'
> 
> I got
> 
> Can't locate loadable object for module DBI in @INC (@INC contains: 
> /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5
> /site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 
> /usr/lib/perl5/site_perl/5.6.0/i386-linux /usr/lib/perl5/site_perl/5.6.0 
> /us
> r/lib/perl5/site_perl .) at 
> /usr/lib/perl5/site_perl/5.6.1/i386-linux/DBI.pm line 255
> BEGIN failed--compilation aborted at 
> /usr/lib/perl5/site_perl/5.6.1/i386-linux/DBI.pm line 255.
> 
> But when I run these two lines as root (super user), I don't
> got above error messages.
> 
> The correct output should be look like
> 
> DynaLoader.pm loaded (/usr/lib/perl5/5.6.1/i386-linux 
> /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux 
> /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0/i386-linux 
> /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl ., 
> /usr/local/lib /lib /usr/lib)
> DynaLoader::bootstrap for DBI (auto/DBI/DBI.so)
> 
> I run these two lines in a different REdhat Linux 7.2 machine.
> 
> I checked the DynaLoader.pm, DBI.pm and DBI.so files,
> they are all inatalled there.
> Do you think something missing with the perl dynamic loader?
> Or I have missing something?
> 
> If you know how to set up this, please let me know.
> I can't access USENET news groups all the time.
> So, can you also Cc to me when you follow up this?
> 


-- 
Ron Reidy
Oracle DBA



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

Date: Wed, 30 Jul 2003 09:50:13 GMT
From: jason@jumpsql.com (Jason Quek)
Subject: Discrepancy in Time?
Message-Id: <3f299387.24932609@news.starhub.net.sg>

When I convert "26 Oct 2003" to epoch seconds,

#-----------------------------------------------------------------
use Time::Local;
$from = timelocal(0, 0, 0, 26, 9, 2003);
# $from == 1067140800;
#-----------------------------------------------------------------

When I convert "27 Oct 2003" to epoch seconds,

#-----------------------------------------------------------------
use Time::Local;
$from = timelocal(0, 0, 0, 26, 9, 2003);
# $to == 1067230800;
#-----------------------------------------------------------------

#-----------------------------------------------------------------
$difference = $to - $from;
# $difference == 90000;
#-----------------------------------------------------------------

Shouldn't the difference between the 26th and 27th be 86400
(60*60/24)? Where did the extra 1 hour come from?


Does anybody know why this happens?


Regards,



Jason Quek
jason@hellcyon.com


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

Date: Wed, 30 Jul 2003 09:46:52 +0200
From: David Bouman <dbo@xbn.nl>
Subject: Re: failed /g match on empty string does not reset pos()
Message-Id: <3F2777EC.6A8CAE2B@xbn.nl>

Steve Grazzini wrote:
> David Bouman <dbo@xbn.nl> wrote:
>
>> For the empty string I'm expecting pos() to have been reset after
>> the failed second match just as it has for the non-empty string.
>>
>> I'm tempted to say it's a bug.
>
> More generally, it looks like the "target is too short" optimization
> isn't resetting pos().
>
>     for ("f") {
>       m/./g;    print pos || "<undef>";
>       m/../g;   print pos || "<undef>";
>     }
>
> If you change the second match to "m/./g" it will reset.

Ok so it *is* a bug then. Has somebody filed a report yet?

--
David


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

Date: Wed, 30 Jul 2003 02:30:44 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: hash problems
Message-Id: <cdbeivo0lma01jd8e89truap2u15jdpabf@4ax.com>

Uri Guttman wrote:

>and you think usenet is the fastest way to get answers?

Note: "time spent on research" ne "time between posting question and
getting an answer".

-- 
	Bart.


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

Date: Wed, 30 Jul 2003 03:55:42 GMT
From: "mgarrish" <mgarrish@rogers.com>
Subject: Re: help with file dialog
Message-Id: <2lHVa.12052$rsJ.10892@news04.bloor.is.net.cable.rogers.com>


"Go Perl" <puissant00@yahoo.com> wrote in message
news:d3825316.0307290829.35a72bc3@posting.google.com...
>
> sub fileDialog {
>     my $w = shift;
>     my $ent = shift;
>     my $operation = shift;
>     my $types;
>     my $file;
>     @types =
>       (["Text files", '*.txt'],
>        ["All files", '*']
>       );
>     if ($operation eq 'open') {
>  $file = $w->getOpenFile(-filetypes => \@types);
>     }
> }

This is the subroutine that gets called when you click on the Browse
buttons, but you have nothing in here to open a file selector window.
Further, you send the operation types 'one', 'two', three' and 'four', which
means that it winds up doing nothing (since only 'open' will trigger your if
condition). If you just want to see a file selector, add the following after
the if statement:

else {
   $FSref = $w->FileSelect(-directory => 'c:\\');
   $file = $FSref->Show;
}

It takes a few minutes to open the FileSelect window on my computer, but it
does show up eventually (your script is not hanging on you).

Matt




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

Date: Tue, 29 Jul 2003 20:33:58 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help with parsing text file
Message-Id: <slrnbie846.643.tadmc@magna.augustmail.com>

Kent <kstairley@coppernospam.com> wrote:

[snip]

>> [ snip TOFU. Please do not do that anymore. ]


I asked you to please stop doing that.

If you do not know what "that" is, then you should have asked.

So long.


   *plonk*


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


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

Date: Wed, 30 Jul 2003 04:18:30 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <bg7a2c$ldv9o$1@ID-184292.news.uni-berlin.de>

Steve Grazzini wrote:
> You can identify real (hard) references with ref().
> 
>     #!/usr/bin/perl -l
> 
>     sub x { }
>     my $soft = 'x';
>     my $hard = \&x;
> 
>     print ref($soft);  # ""
>     print ref($hard);  # "CODE"
> 
> And armed with this knowledge it's not hard to figure out
> that $code is a hard reference:
> 
>     my $code = \&$soft;
>     print ref($code);  # "CODE"
> 
> I think you already knew this, and were asking "why?"...

I did know that. That's what I was referring to when saying that (the
equivalent of) $code _behaved_ like a real/hard reference.

> You started with a soft reference, which is just the 
> *name* of something:
> 
>   1)    $soft  => name of subroutine ("x")
> 
> And then you dereferenced it as a subroutine, yielding
> the sub itself.  That's maybe a tricky concept, since
> you can't touch the subroutine *itself* in Perl.
> 
>   2)   &$soft  => the subroutine itself
> 
> But that's what you have.  And at this point you can do
> anything with "&$soft" that you would have done with "&x",
> including taking a hard reference:
> 
>   3)  \&$soft  => hard reference to subroutine
> 
> Is that clear?

Yes, I'm following every word. :)

Let me try to summarize what I've learned from all the helpful posts
in this thread:

When I stated that I was not using a symbolic reference when doing
&{\&{$array[3]}}, Brian corrected me by pointing to the fact that
after "perldoc strict" has stated that "strict refs" generates a
runtime error if you use symbolic references, it says:

              There is one exception to this rule:

                  $bar = \&{'foo'};
                  &$bar;

If I understand that correctly, the exception that "perldoc strict" is
referring to is

                  $bar = \&{'foo'};
-------------------------^^^^^^^^

the marked part of that expression. In other words, the _symbolic_
reference &{'foo'} is used for creating the _hard_ reference $bar (to
foo).

I didn't get that first, which was the reason for my follow-up question.

As a consequence of the above, I do not (yet?) understand Steven's and
Uri's replies, but I'm posting separate comments to those.

Thanks to everyone who have helped me understand this tricky part of
Perl a little better! I hope that somebody besides me learned 
something from it. :)

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



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

Date: Wed, 30 Jul 2003 04:18:54 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <bg7a34$l8105$1@ID-184292.news.uni-berlin.de>

Steven Kuo wrote:
> On Tue, 29 Jul 2003, Gunnar Hjalmarsson wrote:
>>As far as I can see, $coderef behaves like a real reference.
> 
> $coderef is a symbolic reference.  It's analogous to $symref below:
> 
> no strict;
> use warnings;
> use vars qw($bar $baz);
> 
> our $bar = 'BAR';    # package scoped
> our $baz = 'BAZ';    # package scoped
> 
> my  $foo = 'bar';
> my $symref = \$$foo; # symbolic reference
> 
> $foo = 'baz';        # redefine lexical
> print $$symref;      # dereference symbolic reference
> 
> __END__
> 
> Output:
> BAR

I agree that the above outputs BAR, but doesn't that indicate that 
$symref is a hard reference to 'BAR' (even if it was _created_ using 
the symref construct $$foo)?

Furthermore:

print ref $symref;   # outputs SCALAR

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



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

Date: Wed, 30 Jul 2003 04:19:03 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <bg7a3d$ldv9o$2@ID-184292.news.uni-berlin.de>

Uri Guttman wrote:
>>>>>>"GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> 
>   GH> Steven Kuo replied:
>   >> $coderef is a symbolic reference.
> 
> he meant your use was a symref and not a true coderef. a
> coderef is either an anon sub:
> 
> 	my $code_ref = sub { print "foo\n" } ;
> 
> or a direct hard reference to a named sub:
> 
> 	sub foo { print "foo\n" } ;
> 
> 	my $code_ref = \&foo ;

But how about:

     sub foo { print "foo\n" }
     my $bar = 'foo';
     my $code_ref = \&$bar;

Is $code_ref in that example not a "true" coderef? Even if a symref 
construct was used for _creating_ $code_ref, don't you agree that 
$code_ref is as hard as in the two other examples?

> notice there is no use of a variable containing a name. that
> would be a symref.

I understand that &$bar is a symbolic dereference, but does that in 
any way affect the characteristics of $code_ref?

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



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

Date: Wed, 30 Jul 2003 03:14:11 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <x78yqgpuyl.fsf@mail.sysarch.com>

>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

  GH> Uri Guttman wrote:
  >>>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
  GH> Steven Kuo replied:
  >> >> $coderef is a symbolic reference.
  >> he meant your use was a symref and not a true coderef. a
  >> coderef is either an anon sub:
  >> my $code_ref = sub { print "foo\n" } ;
  >> or a direct hard reference to a named sub:
  >> sub foo { print "foo\n" } ;
  >> my $code_ref = \&foo ;

  GH> But how about:

  GH>      sub foo { print "foo\n" }
  GH>      my $bar = 'foo';
  GH>      my $code_ref = \&$bar;

  GH> Is $code_ref in that example not a "true" coderef? Even if a symref
  GH> construct was used for _creating_ $code_ref, don't you agree that
  GH> $code_ref is as hard as in the two other examples?

it is a hard ref. but it is tainted by how it was created. the issue is
whether a symref is needed at all when dynamicly calling a sub. and the
overall consensus is no.

  >> notice there is no use of a variable containing a name. that
  >> would be a symref.

  GH> I understand that &$bar is a symbolic dereference, but does that in
  GH> any way affect the characteristics of $code_ref?

once you have a real coderef, it makes no matter how you got it. but how
you get it is the whole point of this thread. i said that coderefs are
generally a compile time thing but as you showed it can be done at
runtime. that doesn't make it good.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 30 Jul 2003 03:19:19 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <x765lkpuq0.fsf@mail.sysarch.com>

>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

  GH> Steven Kuo wrote:
  >> On Tue, 29 Jul 2003, Gunnar Hjalmarsson wrote:
  >>> As far as I can see, $coderef behaves like a real reference.
  >> $coderef is a symbolic reference.  It's analogous to $symref below:
  >> no strict;
  >> use warnings;
  >> use vars qw($bar $baz);
  >> our $bar = 'BAR';    # package scoped
  >> our $baz = 'BAZ';    # package scoped
  >> my  $foo = 'bar';
  >> my $symref = \$$foo; # symbolic reference

that is a symbolic DEreference of $foo and then a hard reference to
$bar. $symref has the value of \$bar. the var $symref is poorly named as
it really holds a hard ref.

  >> $foo = 'baz';        # redefine lexical
  >> print $$symref;      # dereference symbolic reference

since $symref refers to $bar at this point, changing $foo won't affect
it.

  >> __END__
  >> Output:
  >> BAR

  GH> I agree that the above outputs BAR, but doesn't that indicate that
  GH> $symref is a hard reference to 'BAR' (even if it was _created_ using
  GH> the symref construct $$foo)?

it is a hard ref to $bar, not to 'BAR'.

  GH> Furthermore:

  GH> print ref $symref;   # outputs SCALAR

which makes sense as it is a ref to the scalar $bar.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 30 Jul 2003 09:38:49 +0000
From: Garry Short <g4rry_sh0rt@zw4llet.com>
Subject: Re: New to Perl
Message-Id: <bg80ck$13f$2$8302bc10@news.demon.co.uk>

Tad McClellan wrote:
> 
> That occurred to me too when I typed the above for the 2nd time in 2 days.
> 
> :-)
> 
> 

Sounds like a repetitive task to me ... have you considered writing a perl
script to automate it?

;-)



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

Date: Tue, 29 Jul 2003 20:30:52 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl - how to compute totals via hash request
Message-Id: <slrnbie7uc.643.tadmc@magna.augustmail.com>

ctcgag@hotmail.com <ctcgag@hotmail.com> wrote:

> Keep two hashes, one named %sum and one named %count,


When you find yourself maintaining 2 "parallel" data structures,
that most often indicates that you have not yet found the
"best" data structure.

Keep one hash of hashes, outer key is the date, 4 inner keys per
date for the 2 running totals and the 2 counts.


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


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

Date: 30 Jul 2003 02:49:56 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: remote readdir()
Message-Id: <slrnbiecim.d0q.mgjv@verbruggen.comdyn.com.au>

On 29 Jul 2003 10:30:09 -0700,
	ARod <Arthurkog@yahoo.com> wrote:
> Garry Short <g4rry_sh0rt@zw4llet.com> wrote in message news:<bg60k7$mo4$2$8300dec7@news.demon.co.uk>...

>> And if you're using some brand of Windoze,
>> 
>> my $remote = '\\remote_server\remote_share\file_structure_within_share';
>> readdir $remote or die "Can't READDIR $remote: $!\n";

> Garry, I'm using Windows NT but your suggestion is not working. 
> Here's a snippet of the code:
> 
> $remote = "\\\\server\\some_share";

Don't use double quotes for this, use singles, unless you like
repeating all those backslashes.

> opendir(DIRECTORY,$remote);

You forgot to check whether the opendir() succeeded. When you do, make
sure to include $! in your error message.

> @dirs=readdir(DIRECTORY) or die "can't read $remote";

Your error message is misleading.

> closedir(DIRECTORY);
> 
> The readdir fails...What am I doing wrong?

You forgot to check whether the opendir() succeeded.

If it fails, there could be a load of reasons, the most likely being
that you are not allowed to connect to that share without providing
credentials.

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | What's another word for Thesaurus?
                        | 


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

Date: Wed, 30 Jul 2003 09:36:35 +0000
From: Garry Short <g4rry_sh0rt@zw4llet.com>
Subject: Re: remote readdir()
Message-Id: <bg808f$13f$1$8302bc10@news.demon.co.uk>

ARod wrote:

> Garry, I'm using Windows NT but your suggestion is not working.
> Here's a snippet of the code:
> 
> $remote = "\\\\server\\some_share";
> 
> opendir(DIRECTORY,$remote);
> @dirs=readdir(DIRECTORY) or die "can't read $remote";
> closedir(DIRECTORY);
> 
> The readdir fails...What am I doing wrong?

There's nothing wrong with the code per se - just ran it on my NT box and it
works fine. The trouble is you're not checking your results properly :

opendir(DIRECTORY,$remote) or die "Can't open DIR $remote: $!\n;
@dirs=readdir(DIRECTORY) or die "can't read $remote: $!\n";

Try that and the script will tell you why it fails. 

BTW, a word of warning - the script will come back and say "No such file or
directory" if you don't have read access, which is a little misleading. If
you get this error and you know the share exists, try opening it within NT
(run command: "\\server\share")

HTH,

Garry




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

Date: 29 Jul 2003 21:12:57 -0700
From: djbitchpimp@snowboard.com (Greg)
Subject: split alternative using regexp?
Message-Id: <7e312ede.0307292012.f45b350@posting.google.com>

Hi everyone

I am trying to teach myself Perl regular expressions and one exercise
that I am having trouble with is duplicating the split function using
regular expressions.

I basically just want to split a sentence of text into individual
words in an array.

Thanks in advance

-Greg


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

Date: Wed, 30 Jul 2003 11:11:11 +0530
From: Thens <thens@nospam.com>
Subject: Re: split alternative using regexp?
Message-Id: <20030730111111.4b16cfb4.thens@nospam.com>

On 29 Jul 2003 21:12:57 -0700
djbitchpimp@snowboard.com (Greg) wrote:

>
>I basically just want to split a sentence of text into individual
>words in an array.
>

  This will do what you want. The general rule is 
 . use split when you know what to ignore
 . use m//  when you know what to retain. 

  In this case you know you want to retain the words. use m/\w+/g.


#!/usr/bin/perl 

use strict;
use warnings;

my ($string, @array);

$string = "This is a looong sentence ";
@array = ( $string =~ m/\w+/g ) ;

print join ( "\n", @array );


OUTPUT :
This
is
a
looong
sentence


Regards,
Thens.



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

Date: 30 Jul 2003 06:37:49 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: split alternative using regexp?
Message-Id: <bg7p3t$afe$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Greg:

> I am trying to teach myself Perl regular expressions and one exercise
> that I am having trouble with is duplicating the split function using
> regular expressions.

Emulating split() with regexes sounds easier than it is. There is no
generic way to turn a split statement into an equivalent match (at least
none I know of). For instance, in a case like

    @p = split /a/, $string;

split() wont care whether $string begins, ends or even contains an 'a'.
It'll just do the right thing. If you use a match instead, you have to
take these different cases into account yourself. Take this:
    
    # the easy case
    my $string = "bbabba";
    my @parts  = $string =~ /(.*?)a/g;
    print join "*", @parts;
    __END__
    bb*bb

This works as expected. But now prepend an 'a':

    my $string = "abbabba";
    my @parts  = $string =~ /(.*?)a/g;
    print join "*", @parts;
    __END__
    *bb*bb

So suddenly you end up having the empty string in $parts[0]. This could
be fixed by adding a grep():

    my $string = "abbabba";
    my @parts  = grep length, $string =~ /(.*?)a/g;
    print join "*", @parts;
    __END__
    bb*bb

But if you let the string end on something other than the delimiter,
it'll fail again:

    my $string = "abbabbac";
    my @parts  = grep length, $string =~ /(.*?)a/g;
    print join "*", @parts;
    __END__
    bb*bb

It should have been 'bb*bb*c' instead. I think with a
lookahead-assertion you could at least come close to split() (provided
the string contains the pattern):

    sub my_split {
        my ($pat, $string) = @_;
        return grep defined && length, 
               $string =~ /(.+?)?$pat(.+?)(?=$pat|$)/g;
    }

But I've already found a dozen of cases where it does not work like
split().

> I basically just want to split a sentence of text into individual
> words in an array.

So use split:

    my @words = split /\W+/, $sentence;

As for your little excercise, I am sure there are more suitable things
than mimicing split() that you could practice with regular expressions.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Wed, 30 Jul 2003 02:29:11 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Win32 Ole
Message-Id: <a3beiv4dk4barh3f1u87s2bs4h49t4lf6m@4ax.com>

Mike Flannigan wrote:

>I got the following code from the examples on
>http://aspn.activestate.com//ASPN/Products/ActivePerl/site/lib/Win32/OLE.html#examples
>
>When I try to run it, it gives me:
>Can't find string terminator "Overload" anywhere before EOF at
>C:/Perl/lib/Win32/OLE.pm line 29.
>Compilation failed in require at excel.pl line 4.
>BEGIN failed--compilation aborted at excel.pl line 4.

It seems to me like your script may be fine, but this really sounds like
a here-doc problem in the module. How did you install it?

>I see that OLE.pm has "Overload" on line 59 and line 65 and a few
>other places, but not anywhere near line 29.  Any ideas why this is
>not working?  I'm very new to modules, but have gotten some to
>work in the past.

On my system, line 29 reads

		    eval <<'OVERLOAD';

The equivalent end delimiter is on line 33... It should just be the word
"OVERLOAD" on its own line, with no additional whitespace around it,
whatsoever. I think that is not the case.

So: how did you install it?

(p.s. And what's up with the case, with you? It's "Win32::OLE", not
"Win32::Ole", and that word is "OVERLOAD3, not "Overload".)

-- 
	Bart.


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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


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