[29681] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 925 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 10 21:09:40 2007

Date: Wed, 10 Oct 2007 18:09:09 -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, 10 Oct 2007     Volume: 11 Number: 925

Today's topics:
        A problem with tr <dn.perl@gmail.com>
    Re: A problem with tr <mgjv@tradingpost.com.au>
    Re: A problem with tr <jgibson@mail.arc.nasa.gov>
    Re: file uploader script <noreply@gunnar.cc>
        Help with regular expression please? <b-patton@ti.com>
    Re: Help with regular expression please? <see.sig@rochester.rr.com>
    Re: https access - NET::SSL or Crypt::SSLeay ?  <wheeledBob@yahoo.com>
    Re: Regular Expression $1? <tadmc@seesig.invalid>
    Re: required perl programmer <tadmc@seesig.invalid>
        string compare problem <chavanpriya@gmail.com>
    Re: string compare problem <usenet@larseighner.com>
    Re: string compare problem <chavanpriya@gmail.com>
    Re: string compare problem <jgibson@mail.arc.nasa.gov>
    Re: string compare problem <usenet@larseighner.com>
    Re: string compare problem <chavanpriya@gmail.com>
    Re: string compare problem <ben@morrow.me.uk>
        UTF8 strings and filesystem access (Gary E. Ansok)
    Re: UTF8 strings and filesystem access <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Oct 2007 22:34:44 -0000
From:  "dn.perl@gmail.com" <dn.perl@gmail.com>
Subject: A problem with tr
Message-Id: <1192055684.268534.139670@g4g2000hsf.googlegroups.com>


Code being run under ActiveState Perl (latest download) :
my $str1 = "11,11,2222,3" ;
$str1 =~ tr/,// ;
print "$str1 \n" ;

my $str2 = "11,11,2222,3" ;
$str2 =~ tr/,/Z/ ;
print "$str2 \n" ;
===

Output :
11,11,2222,3
11Z11Z2222Z3

So I am able to replace comma with 'Z' , but I am not able to make it
disappear using tr.
Why is that so?

Please advise. Thanks in advance.



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

Date: Thu, 11 Oct 2007 09:14:08 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: A problem with tr
Message-Id: <slrnfgqn60.81v.mgjv@martien.heliotrope.home>

On Wed, 10 Oct 2007 22:34:44 -0000,
        dn.perl@gmail.com <dn.perl@gmail.com> wrote:

> my $str1 = "11,11,2222,3" ;
> $str1 =~ tr/,// ;
> print "$str1 \n" ;
>
> my $str2 = "11,11,2222,3" ;
> $str2 =~ tr/,/Z/ ;
> print "$str2 \n" ;
>===
>
> Output :
> 11,11,2222,3
> 11Z11Z2222Z3
>
> So I am able to replace comma with 'Z' , but I am not able to make it
> disappear using tr.
> Why is that so?

From the documentation of tr/// in the perlop document [1]:

           Options:

               c   Complement the SEARCHLIST.
               d   Delete found but unreplaced characters.
               s   Squash duplicate replaced characters.

           If the "/c" modifier is specified, the SEARCHLIST character set
           is complemented.  If the "/d" modifier is specified, any char-
           acters specified by SEARCHLIST not found in REPLACEMENTLIST are
           deleted.

But also, and this, I assume, is the source of your confusion:

           If the "/d" modifier is used, the REPLACEMENTLIST is always
           interpreted exactly as specified.  Otherwise, if the REPLACE-
           MENTLIST is shorter than the SEARCHLIST, the final character is
           replicated till it is long enough.  If the REPLACEMENTLIST is
           empty, the SEARCHLIST is replicated.  This latter is useful for
           counting characters in a class or for squashing character
           sequences in a class.

I suspect that what you're looking for is:

$str1 =~ tr/,//d;

Martien

[1] You can get to the documentation by using the man command on a
Unix-like OS, perldoc on almost any OS, and from HTML pages on some
distibutions. If you don't already know this, please take some time to
get familiar with Perl's documentation and your system's way of making
it available to you.

-- 
                        | 
Martien Verbruggen      | There are only 10 types of people in the
                        | world; those who understand binary and those
                        | who don't.


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

Date: Wed, 10 Oct 2007 16:52:45 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: A problem with tr
Message-Id: <101020071652454674%jgibson@mail.arc.nasa.gov>

In article <1192055684.268534.139670@g4g2000hsf.googlegroups.com>,
<"dn.perl@gmail.com"> wrote:

> Code being run under ActiveState Perl (latest download) :
> my $str1 = "11,11,2222,3" ;
> $str1 =~ tr/,// ;
> print "$str1 \n" ;
> 
> my $str2 = "11,11,2222,3" ;
> $str2 =~ tr/,/Z/ ;
> print "$str2 \n" ;
> ===
> 
> Output :
> 11,11,2222,3
> 11Z11Z2222Z3
> 
> So I am able to replace comma with 'Z' , but I am not able to make it
> disappear using tr.
> Why is that so?

Because it is implemented that way. See 'perldoc perlop' and search for
'SEARCHLIST'.

Short answer: Use tr/,//d;

The rule is that if the replacement list is empty and the d modifier is
not specified, the search list is also used as the replacement list. In
that case, no replacements are done, but you get a count of the
characters in the string.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Thu, 11 Oct 2007 02:41:54 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: file uploader script
Message-Id: <5n59qsFgckmdU1@mid.individual.net>

ll wrote:
> On Oct 10, 10:07 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
>> If that script doesn't work as expected, please consult the
>> documentation or the script author.
>>
>> If you want to write your own script, and are encountering difficulties
>> when doing so, this group may be a good place to ask for help. Btw, you
>> may want to make use of the CPAN module CGI::UploadEasy.
> 
> Thanks for your reply.  I've now got the files to upload (to "cgi-bin/
> upload/" - for some reason I cannot get them to upload to "root/
> upload/".

I had a look at the script's config variables. Try this setting:

$parent_dir = "$ENV{DOCUMENT_ROOT}/";

> I am able to open the files from the ftp client, although
> when I try opening them via the link created (which turns out to be
> the empty "root/upload/" directory) on the page, I get the following
> error:
> "Not Found
> The requested URL /upload/comm_khicks.gif was not found on this
> server.
> Additionally, a 404 Not Found error was encountered while trying to
> use an ErrorDocument to handle the request. "
> 
> I would like a way to view/open the files within the "root/upload/"
> directory.

As long as the files are not saved in that directory, you can't 
reasonably be expecting to view/open the files there, can you?

> Thanks for the tip re CGI::UploadEasy.

You're welcome. Note, again, that this group is for discussing Perl 
programming, not for assistance with ready-to-use scripts.

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


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

Date: Wed, 10 Oct 2007 15:17:21 -0500
From: "Billy N. Patton" <b-patton@ti.com>
Subject: Help with regular expression please?
Message-Id: <fejc0i$rhu$1@home.itg.ti.com>

Here is the simplified code I have attempted.  It failed me by finding 31ZB1 to be the same as 31ZB11

__BEGIN__

$focusRule = '31ZB1';
# match            v                               v      v      v
@l = ( qw ( 31ZA1 31ZB1 31ZB11 31ZB15 175A2 31ZU7 31ZB 31ZB1a 31ZB1b ));
# n = number 

# a = alpha char 

# + is one or more 

# ? one or more may or may not be there 

# the rule names are built 

# n+a+n?a?n? 

# so the possible correect permutations are 

# n+a+ 

# n+a+n+ 

# n+a+n+a+ 

# n+a+n+a+n+ 

# 31ZB1 31ZB 31ZB1a 31ZB1b1  all these should match $focusRule 

# 31ZB1 and 31ZB11 are different 

# I also need to set $focusRule to '31ZB' and have it find the same set. 

$found = 0;
foreach $rule (@l ) {
   my $a1 = ($rule =~ /^$focusRule[abc123]?$|,$focusRule[abc123]/) ? 1 : 0;
   my $a2 = ($focusRule =~ /^$rule[abc123]?/) ? 1 : 0;
   print "focusRule = '$focusRule' , rule = '$rule', a1 = $a1 , a2 = $a2\n";
   if ($a1 || $a2) {
     print "focusRule = '$focusRule' matches '$rule'\n";
     $found++;
   }
}
print "found = $found\nshould have found 4";


__END__


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

Date: Wed, 10 Oct 2007 20:57:42 -0400
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: Help with regular expression please?
Message-Id: <470d7507$0$24273$4c368faf@roadrunner.com>

Billy N. Patton wrote:
> Here is the simplified code I have attempted.  It failed me by finding 
> 31ZB1 to be the same as 31ZB11
> 
> __BEGIN__
> 
> $focusRule = '31ZB1';
> # match            v                               v      v      v
> @l = ( qw ( 31ZA1 31ZB1 31ZB11 31ZB15 175A2 31ZU7 31ZB 31ZB1a 31ZB1b ));
> # n = number
> # a = alpha char
> # + is one or more
> # ? one or more may or may not be there
> # the rule names are built
> # n+a+n?a?n?
> # so the possible correect permutations are
> # n+a+
> # n+a+n+
> # n+a+n+a+
> # n+a+n+a+n+
> # 31ZB1 31ZB 31ZB1a 31ZB1b1  all these should match $focusRule
> # 31ZB1 and 31ZB11 are different
> # I also need to set $focusRule to '31ZB' and have it find the same set.
> $found = 0;
> foreach $rule (@l ) {
>   my $a1 = ($rule =~ /^$focusRule[abc123]?$|,$focusRule[abc123]/) ? 1 : 0;
>   my $a2 = ($focusRule =~ /^$rule[abc123]?/) ? 1 : 0;
>   print "focusRule = '$focusRule' , rule = '$rule', a1 = $a1 , a2 = $a2\n";
>   if ($a1 || $a2) {
>     print "focusRule = '$focusRule' matches '$rule'\n";
>     $found++;
>   }
> }
> print "found = $found\nshould have found 4";
> 
> 
> __END__

Well, note that

    '31ZB11'=~/^31ZB1[abc123]?$/;

will match.  I presume from your comments (if I read them correctly) 
that you thought that one would not match.  Not sure why, since you 
recognize that

    '31ZB1a'=~/^31ZB1[abc123]?$/;

for example, will match.  If you meant something else, please clarify.

Also, I don't follow your bit after the alternation symbol in your "my 
$a1 ..." line.  None of your attempted match strings have a comma in 
them, so the second alternative will never succeed.

If you haven't already, you might try:

    use re 'debug';

for useful information about complex regular expression matches.

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: Wed, 10 Oct 2007 22:56:42 GMT
From: still me <wheeledBob@yahoo.com>
Subject: Re: https access - NET::SSL or Crypt::SSLeay ? 
Message-Id: <03mqg3p7rrs738iopp9nl1gm6kg5cvn54l@4ax.com>

On Wed, 10 Oct 2007 20:34:38 GMT, still me <wheeledBob@yahoo.com>
wrote:

>
>I need to pull a web page with Perl and echo it back. I am familiar
>with crude LWP use (crude 'cause I'm a newbie). I understand that to
>pull from an https server I will need NET::SSL or Crypt::SSLeay.
>
>Will NET::SSL do the job? I have a feeling that it will be easier to
>get my host to install that, although I have asked for both. 
>
>Also, could someone post a simple example of pulling a page with it? I
>don't need password access & such, just a very simple pull of a page
>from an https server that I will echo back to the calling browser. 

Following up... I have found that Crypt::SSLeay is already installed.
NET::SSL is not there... waiting for my host to get back to me. 

If there is a sample around of Crypt::SSLeay with a post operation
that would help. 

TA, 



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

Date: Wed, 10 Oct 2007 19:54:05 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Regular Expression $1?
Message-Id: <slrnfgqt1d.5s6.tadmc@tadmc30.sbcglobal.net>

Cloink <Cloink_Friggson@ntlworld.com> wrote:

> Paul - well done for answering lucidly, it doesn't happen often, esp
> not on Perl pages.


It is likely that the results you have observed correlate
with the attitude that you have displayed here in the past.

Insulting people does not motivate them to be helpful.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 10 Oct 2007 19:45:51 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: required perl programmer
Message-Id: <slrnfgqshv.5s6.tadmc@tadmc30.sbcglobal.net>

susheel <tatasushil@gmail.com> wrote:


> send me an up dated resume to susheel@noblesystemsware.com


Job postings are off-topic in this newsgroup.

Postings from recruiters, rather than from employers, is
outright reviled here.

Get thee to http://jobs.perl.org instead.



(Good Perl programmers are hard to come by in the Metroplex,
 my employer has been looking for some more for a while...
)

-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 10 Oct 2007 23:16:09 -0000
From:  pc <chavanpriya@gmail.com>
Subject: string compare problem
Message-Id: <1192058169.572978.247310@o80g2000hse.googlegroups.com>

I have field1 and field3 contain date time values in form of a
string.For example:10/3/2006 8:02:49 ,10/3/2006 8:16:40.I break them
into 2 seperate date and time fields like this:

($datepart1,$timepart1) = split ' ', $field1;
($datepart3,$timepart3) = split ' ', $field3;

Now I want to check if the value of datepart1 and datepart3 are
unequal.


if($datepart1 ne $datepart3){
		print ERROR;
}


This "if code" doesnt seam to work.When i print the values of
datepart1 and datepart3 before entering the if loop,they are not equal
but stilll the error message does not get printed on the screen.



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

Date: 10 Oct 2007 23:45:44 GMT
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: string compare problem
Message-Id: <slrnfgqovc.2ku.usenet@debranded.larseighner.com>

In our last episode,
<1192058169.572978.247310@o80g2000hse.googlegroups.com>, the lovely and
talented pc broadcast on comp.lang.perl.misc:

> I have field1 and field3 contain date time values in form of a
> string.For example:10/3/2006 8:02:49 ,10/3/2006 8:16:40.I break them
> into 2 seperate date and time fields like this:

> ($datepart1,$timepart1) = split ' ', $field1;
> ($datepart3,$timepart3) = split ' ', $field3;

> Now I want to check if the value of datepart1 and datepart3 are
> unequal.


> if($datepart1 ne $datepart3){
> 		print ERROR;
> }


> This "if code" doesnt seam to work.When i print the values of
> datepart1 and datepart3 before entering the if loop,they are not equal
> but stilll the error message does not get printed on the screen.

What is ERROR?


-- 
Lars Eighner     <http://larseighner.com/>     <http://myspace.com/larseighner>
                         Countdown: 467 days to go.
                    What do you do when you're debranded?


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

Date: Wed, 10 Oct 2007 23:52:59 -0000
From:  pc <chavanpriya@gmail.com>
Subject: Re: string compare problem
Message-Id: <1192060379.956734.72680@r29g2000hsg.googlegroups.com>

The error is that even though the values of datepart1 and datepart3
are not equal the message "ERROR" does not get printed on screen.
For example say field1=7/31/2007 7:39:22 and field3=7/30/2007
8:11:02.Now when I do

($datepart1,$timepart1) = split ' ', $field1;
($datepart3,$timepart3) = split ' ', $field3;
 if($datepart1 ne $datepart3){
            print ERROR;
 }


I expect that the message "ERROR" prints on the screen.My problem is
that it doesnt.







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

Date: Wed, 10 Oct 2007 16:58:10 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: string compare problem
Message-Id: <101020071658104138%jgibson@mail.arc.nasa.gov>

In article <1192058169.572978.247310@o80g2000hse.googlegroups.com>, pc
<chavanpriya@gmail.com> wrote:

> I have field1 and field3 contain date time values in form of a
> string.For example:10/3/2006 8:02:49 ,10/3/2006 8:16:40.I break them
> into 2 seperate date and time fields like this:
> 
> ($datepart1,$timepart1) = split ' ', $field1;
> ($datepart3,$timepart3) = split ' ', $field3;
> 
> Now I want to check if the value of datepart1 and datepart3 are
> unequal.
> 
> 
> if($datepart1 ne $datepart3){
>     print ERROR;
> }
> 
> 
> This "if code" doesnt seam to work.When i print the values of
> datepart1 and datepart3 before entering the if loop,they are not equal
> but stilll the error message does not get printed on the screen.
> 

In Perl, you need to enclose strings in some sort of quotes:

  print "ERROR";
  print 'ERROR';
  print q(ERROR);
  print qq(ERROR);

If you had put 'use warnings;' at the beginning of your program, Perl
would have told you why your program isn't doing what you think it
should be.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: 11 Oct 2007 00:01:13 GMT
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: string compare problem
Message-Id: <slrnfgqpse.5ge.usenet@debranded.larseighner.com>

In our last episode, 
<1192060379.956734.72680@r29g2000hsg.googlegroups.com>, 
the lovely and talented pc 
broadcast on comp.lang.perl.misc:

> The error is that even though the values of datepart1 and datepart3
> are not equal the message "ERROR" does not get printed on screen.
> For example say field1=7/31/2007 7:39:22 and field3=7/30/2007
> 8:11:02.Now when I do

> ($datepart1,$timepart1) = split ' ', $field1;
> ($datepart3,$timepart3) = split ' ', $field3;
>  if($datepart1 ne $datepart3){
>             print ERROR;
>  }


> I expect that the message "ERROR" prints on the screen.My problem is
> that it doesnt.

Then make it a string, because the value of ERROR is empty, whereas
the value of 'ERROR' is ERROR.



-- 
Lars Eighner     <http://larseighner.com/>     <http://myspace.com/larseighner>
                         Countdown: 467 days to go.
                    What do you do when you're debranded?


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

Date: Thu, 11 Oct 2007 00:02:46 -0000
From:  pc <chavanpriya@gmail.com>
Subject: Re: string compare problem
Message-Id: <1192060966.201589.171920@y42g2000hsy.googlegroups.com>

On Oct 10, 4:58 pm, Jim Gibson <jgib...@mail.arc.nasa.gov> wrote:
> In article <1192058169.572978.247...@o80g2000hse.googlegroups.com>, pc
>
>
>
>
>
> <chavanpr...@gmail.com> wrote:
> > I have field1 and field3 contain date time values in form of a
> > string.For example:10/3/2006 8:02:49 ,10/3/2006 8:16:40.I break them
> > into 2 seperate date and time fields like this:
>
> > ($datepart1,$timepart1) = split ' ', $field1;
> > ($datepart3,$timepart3) = split ' ', $field3;
>
> > Now I want to check if the value of datepart1 and datepart3 are
> > unequal.
>
> > if($datepart1 ne $datepart3){
> >     print ERROR;
> > }
>
> > This "if code" doesnt seam to work.When i print the values of
> > datepart1 and datepart3 before entering the if loop,they are not equal
> > but stilll the error message does not get printed on the screen.
>
> In Perl, you need to enclose strings in some sort of quotes:
>
>   print "ERROR";
>   print 'ERROR';
>   print q(ERROR);
>   print qq(ERROR);
>
> If you had put 'use warnings;' at the beginning of your program, Perl
> would have told you why your program isn't doing what you think it
> should be.
>
> --
> Jim Gibson
>
>  Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
>     ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------        
>                http://www.usenet.com- Hide quoted text -
>
> - Show quoted text -

Thank you Jim and Lars!



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

Date: Thu, 11 Oct 2007 01:33:16 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: string compare problem
Message-Id: <cj70u4-ja22.ln1@osiris.mauzo.dyndns.org>


Quoth Lars Eighner <usenet@larseighner.com>:
> Then make it a string, because the value of ERROR is empty, whereas
> the value of 'ERROR' is ERROR.

No, ERROR calls the sub ERROR; unless it doesn't exist and use strict
'subs' is not in effect, when it is autoquoted to 'ERROR'.

The OP is probably not using strictures (tut).

Ben



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

Date: Wed, 10 Oct 2007 23:11:11 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: UTF8 strings and filesystem access
Message-Id: <fejm6f$cpb$1@naig.caltech.edu>

One way to access the files in a directory is

    opendir DH, $dir or die "opendir: $!";
    while (my $file = readdir DH) {
        next unless -f "$dir/$file";
        # do whatever needs to be done with "$dir/$file";
    }

However, this fails given the combination of two facts:
  1)  $dir is encoded internally in UTF8 (even if $dir doesn't 
           contain any non-ASCII characters)
  2)  $file contains non-ASCII characters

The string "$dir/$file" becomes UTF8-encoded, and while it
prints correctly, and compares equal to the same string not
UTF8-encoded, apparently the internal encoding is used
in a stat() (or open()) call, which then fails with $! being
"No such file".

Is there a way to work around this without needing to
transcode all strings that might be UTF8-encoded?  $dir is
being read in from a config file using a module (XML::Simple),
so I don't have a lot of control over how it's initialized.

I know I could recast the code to chdir() to $dir, but that
would be a significant change given the current code structure.

This is on Solaris, using 5.8.0, though I've verified
similar behavior on Windows with 5.8.7.  I've tried different
settings for LC_ALL, and it doesn't seem to make a difference.

Below is a more complete program to demonstrate the bug.  It
assumes that a directory "t2" already exists, with 
suitably-named file in it (I used "fil\351.txt")

Thanks,
Gary Ansok

#! /opt/perl/5.8.0/bin/perl

use strict;
use warnings;

my $show_bug = 1;

my $dir = 't2';
if ($show_bug) {      # force $dir to be UTF8-encoded
    $dir .= "\x{100}";
    chop $dir;
}

print "Opening dir '$dir'\n";
opendir DH, $dir or die "opendir: $!";

while (my $file = readdir DH) {
    print "Checking file '$dir/$file'\n";
    next unless -f "$dir/$file";
    print "Found file '$dir/$file'\n";
}


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

Date: Thu, 11 Oct 2007 01:31:13 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: UTF8 strings and filesystem access
Message-Id: <hf70u4-ja22.ln1@osiris.mauzo.dyndns.org>


Quoth ansok@alumni.caltech.edu (Gary E. Ansok):
> One way to access the files in a directory is
> 
>     opendir DH, $dir or die "opendir: $!";
>     while (my $file = readdir DH) {
>         next unless -f "$dir/$file";
>         # do whatever needs to be done with "$dir/$file";
>     }
> 
> However, this fails given the combination of two facts:
>   1)  $dir is encoded internally in UTF8 (even if $dir doesn't 
>            contain any non-ASCII characters)
>   2)  $file contains non-ASCII characters
> 
> The string "$dir/$file" becomes UTF8-encoded, and while it
> prints correctly, and compares equal to the same string not
> UTF8-encoded, apparently the internal encoding is used
> in a stat() (or open()) call, which then fails with $! being
> "No such file".
> 
> Is there a way to work around this without needing to
> transcode all strings that might be UTF8-encoded?

No, not with current versions of perl. All interactions with the system
use raw byte-strings[1], so you will need to encode them correctly in
your local character set for open, and decode them from readdir.

Ben

[1] The -C switch used to switch to the Unicode API on Win32, but noone
used it and the switch was removed in 5.8.1.



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

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


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

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

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


------------------------------
End of Perl-Users Digest V11 Issue 925
**************************************


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