[29923] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1166 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 3 06:50:06 2008

Date: Thu, 3 Jan 2008 03:49:56 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 3 Jan 2008     Volume: 11 Number: 1166

Today's topics:
        Question about "?" character in Perl Regular Expression <ahmad.abdulghany@gmail.com>
    Re: Question about "?" character in Perl Regular Expres <thepoet_nospam@arcor.de>
    Re: Question about "?" character in Perl Regular Expres <jimsgibson@gmail.com>
    Re: Question about "?" character in Perl Regular Expres <mritty@gmail.com>
    Re: Question about "?" character in Perl Regular Expres <jurgenex@hotmail.com>
    Re: Question about "?" character in Perl Regular Expres <someone@example.com>
    Re: Question about "?" character in Perl Regular Expres <mtbr0228AT@sbcglobalDOT.net>
        quick? wiki  project. QoS@domain.invalid
        Reading files created by CGi <visitprakashindia@gmail.com>
    Re: Reading files created by CGi <RedGrittyBrick@SpamWeary.Foo>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <tzz@lifelogs.com>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <abigail@abigail.be>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <tzz@lifelogs.com>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <abigail@abigail.be>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <tzz@lifelogs.com>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <abigail@abigail.be>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <tzz@lifelogs.com>
        split file with according to size <sarma.nedunuri@gmail.com>
    Re: split file with according to size <simon.chao@fmr.com>
    Re: split file with according to size <purlgurl@purlgurl.net>
    Re: split file with according to size <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 1 Jan 2008 23:58:14 -0800 (PST)
From: Ahmad <ahmad.abdulghany@gmail.com>
Subject: Question about "?" character in Perl Regular Expression
Message-Id: <ef21aa83-8fd8-49ec-b28c-fdec39c8db08@u10g2000prn.googlegroups.com>

When running the following example:

$str="aaaaaa   bbbb";
($a,$b)= $str=~/(\w+)\s?(\w+)/;
print $a,"\n",$b;

The result is:

aaaaa
a

Why do we get this result??? Can anybody explain it?
thanks and regards,
Ahmad


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

Date: Wed, 02 Jan 2008 09:43:01 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Question about "?" character in Perl Regular Expression
Message-Id: <477b4e95$0$16666$9b4e6d93@newsspool3.arcor-online.net>

Ahmad wrote:
> When running the following example:
> 
> $str="aaaaaa   bbbb";
> ($a,$b)= $str=~/(\w+)\s?(\w+)/;
> print $a,"\n",$b;
> 
> The result is:
> 
> aaaaa
> a
> 
> Why do we get this result??? Can anybody explain it?

The regex you're using says:
- match (greedily) any number of word characters
- followed by one or zero whitespaces
- followed by any number of word characters

The only possible place where "one or zero whitespaces
followed by a word character" can match directly after a
word character is inside the "aaaaaa" substring.

You most probably want to use "+" instead of "?" as
the whitespace quantifier (match one or more occurences).
($a,$b)= $str=~/(\w+)\s+(\w+)/;

-Chris


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

Date: Wed, 02 Jan 2008 09:52:58 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Question about "?" character in Perl Regular Expression
Message-Id: <020120080952586831%jimsgibson@gmail.com>

In article <477b4e95$0$16666$9b4e6d93@newsspool3.arcor-online.net>,
Christian Winter <thepoet_nospam@arcor.de> wrote:

> Ahmad wrote:
> > When running the following example:
> > 
> > $str="aaaaaa   bbbb";
> > ($a,$b)= $str=~/(\w+)\s?(\w+)/;
> > print $a,"\n",$b;
> > 
> > The result is:
> > 
> > aaaaa
> > a
> > 
> > Why do we get this result??? Can anybody explain it?
> 
> The regex you're using says:
> - match (greedily) any number of word characters
> - followed by one or zero whitespaces
> - followed by any number of word characters
> 
> The only possible place where "one or zero whitespaces
> followed by a word character" can match directly after a
> word character is inside the "aaaaaa" substring.

Well, to be precise, it could also match inside the "bbbb" substring at
any of three positions, but it doesn't get that far because of the
earlier match.

-- 
Jim Gibson

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


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

Date: Wed, 2 Jan 2008 11:54:37 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Question about "?" character in Perl Regular Expression
Message-Id: <5fd29145-4a9e-4274-b21b-104d028d2c39@e10g2000prf.googlegroups.com>

On Jan 2, 2:58=A0am, Ahmad <ahmad.abdulgh...@gmail.com> wrote:
> When running the following example:
>
> $str=3D"aaaaaa =A0 bbbb";
> ($a,$b)=3D $str=3D~/(\w+)\s?(\w+)/;
> print $a,"\n",$b;
>
> The result is:
>
> aaaaa
> a
>
> Why do we get this result??? Can anybody explain it?

Christian already explained to you the difference between ? and +, but
perhaps you were also (or rather) confused about what \s actually is.
You may be thinking that \s means simply "whitespace".  It actually
means "any single white-space character".  It is any ONE character
from the group: space, tab, newline, carriage return, or vertical
tab.   If you want to match more than one character in sequence, you
must use the quantifiers (+, or *, or {n}, depending on your needs)

Hope that helps,
Paul Lalli


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

Date: Wed, 02 Jan 2008 20:07:15 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Question about "?" character in Perl Regular Expression
Message-Id: <umrnn315rbrjh056l4idqp4f0r5h39oa93@4ax.com>

Ahmad <ahmad.abdulghany@gmail.com> wrote:
>When running the following example:
>
>$str="aaaaaa   bbbb";
>($a,$b)= $str=~/(\w+)\s?(\w+)/;
>print $a,"\n",$b;
>
>The result is:
>
>aaaaa
>a
>
>Why do we get this result???

What did you expect instead?

jue


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

Date: Wed, 02 Jan 2008 20:13:12 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Question about "?" character in Perl Regular Expression
Message-Id: <sfSej.43827$UZ4.32635@edtnps89>

Paul Lalli wrote:
> On Jan 2, 2:58 am, Ahmad <ahmad.abdulgh...@gmail.com> wrote:
>> When running the following example:
>>
>> $str="aaaaaa   bbbb";
>> ($a,$b)= $str=~/(\w+)\s?(\w+)/;
>> print $a,"\n",$b;
>>
>> The result is:
>>
>> aaaaa
>> a
>>
>> Why do we get this result??? Can anybody explain it?
> 
> Christian already explained to you the difference between ? and +, but
> perhaps you were also (or rather) confused about what \s actually is.
> You may be thinking that \s means simply "whitespace".  It actually
> means "any single white-space character".  It is any ONE character
> from the group: space, tab, newline, carriage return, or vertical
> tab.

Perl doesn't use the vertical tab.  That should be the group: space, 
horizontal tab, new line, carriage return or form feed.


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Thu, 03 Jan 2008 07:50:31 GMT
From: Alan_C <mtbr0228AT@sbcglobalDOT.net>
Subject: Re: Question about "?" character in Perl Regular Expression
Message-Id: <bt0fj.1409$pA7.1154@newssvr25.news.prodigy.net>

Ahmad wrote:

> When running the following example:
> 
> $str="aaaaaa   bbbb";
> ($a,$b)= $str=~/(\w+)\s?(\w+)/;
> print $a,"\n",$b;
> 
> The result is:
> 
> aaaaa
> a
> 
> Why do we get this result??? Can anybody explain it?

(how you've used it) Like they've replied the ? simply makes the \s optional
as in it will match with or without \s in $str

(not how you've used it) Yet another or one more use (.+? and .*? only) (I
think) is to negate greed

$str="aaaaaa   -bbbb   -ccc";
($a,$b)= $str=~/(\w+).+?-(\w+)/; # negate greed
print $a,"\n",$b;
($a,$b)= $str=~/(\w+).+-(\w+)/;
print "\n\n", $a,"\n",$b, "\n";
# end

-- 
AC



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

Date: Thu, 03 Jan 2008 02:18:17 GMT
From: QoS@domain.invalid
Subject: quick? wiki  project.
Message-Id: <JBXej.8581$tK5.3784@trndny03>


Hello everybody,

Looking for a bit of direction here; just inheirited a wiki project and
would like some pointers on this topic.  I have done some investigating
and am trying to decide on using either Wiki::Toolkit or MediaWiki (PHP),
any help on which to choose would be appreciated.  Another thing that will
be helpful is a book or link suggestion, or perhaps a suggestion on using
a completly different method for getting started with this.  This wiki
will not likely see alot of usage, perhaps 5 simultaenous users or so;
the wiki should be easy to use, I am not much into graphics or web pages
and such; so any solution that will template the look and feel of this
would be ideal.

Thanks CLPM,

J



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

Date: Thu, 3 Jan 2008 01:16:06 -0800 (PST)
From: Praki <visitprakashindia@gmail.com>
Subject: Reading files created by CGi
Message-Id: <f68f4a19-44ba-4f83-a0aa-539da7b14432@t1g2000pra.googlegroups.com>

Hi All,

I have some files created by CGI -Perl in Apache server.i could not
veiw those files using the ls cmd. it does not have permissions.When i
try to read using the CGI-Perl program i could do that. But when i try
to do the same using the Perl (filename.pl) i could not read that.how
can i read that file.is there any way to do that.

Thanks,
Prakash


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

Date: Thu, 3 Jan 2008 10:16:54 -0000
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.Foo>
Subject: Re: Reading files created by CGi
Message-Id: <MPG.21e6c66f36f4bdae989680@news.zen.co.uk>

In article <f68f4a19-44ba-4f83-a0aa-539da7b14432
@t1g2000pra.googlegroups.com>, visitprakashindia@gmail.com says...
> Hi All,
> 
> I have some files created by CGI -Perl in Apache server.i could not
> veiw those files using the ls cmd. it does not have permissions.When i
> try to read using the CGI-Perl program i could do that. But when i try
> to do the same using the Perl (filename.pl) i could not read that.how
> can i read that file.is there any way to do that.
> 

It is almost certainly a case of file access permissions. On a Unix 
system, Apache will run CGI programs using the User-ID of the Apache 
process. Any files created will be owned by that User-ID and will have 
permissions dictated (I guess) by the UMASK value in effect for that 
process.

In the CGI script that creates the files you can insert an appropriate 
chmod command to change the read permissions to something more suitable 
to your needs.

If you can't alter the CGI script then you need to contact the 
administrator of the web server.

see `perldoc -f chmod`


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

Date: Mon, 31 Dec 2007 08:09:18 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <86d4snx8fl.fsf@lifelogs.com>

On 29 Dec 2007 00:23:55 GMT Abigail <abigail@abigail.be> wrote: 

A> With 5.10, you can do it with A and B patterns:

A>     use 5.010;
A>     our $REGMARK;
A>     my %replacement = qw [X B Y C];
A>     $_ = "AABDAAABBE";
A>     s/(*:X)A(?{})|(*:Y)B/$replacement{$REGMARK}/g;
A>     say;
A>     __END__
A>     BCDBCE

A> Note that the (?{}) is there to prevent a bug from triggering.

On Sat, 29 Dec 2007 14:45:17 +0100 "Dr.Ruud" <rvtol+news@isolution.nl> wrote: 

R> If string-A can ever be a subpattern of string-B, then you need to add a
R> "longest first" approach.
 ...
R> (or use a different regex-engine :)

Abigail's 5.10 solution doesn't scale well, and Dr. Ruud's longest-first
solution (which others suggested but without the longest-first fix) is
closest to a generic solution.  It won't help if the list contains
regular expressions, but for fixed strings it's the best I can see.  I'd
just build the match alternation with something like this:

sprintf "(%s)", join('|', sort { length $a <=> length $b } keys %patterns);

Thanks for all the suggestions.

Ted


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

Date: 31 Dec 2007 23:18:23 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <slrnfniu5v.i0.abigail@alexandra.abigail.be>

                                         _
Ted Zlatanov (tzz@lifelogs.com) wrote on VCCXXXV September MCMXCIII in
<URL:news:86d4snx8fl.fsf@lifelogs.com>:
^^  On 29 Dec 2007 00:23:55 GMT Abigail <abigail@abigail.be> wrote: 
^^  
^^  A> With 5.10, you can do it with A and B patterns:
^^  
^^  A>     use 5.010;
^^  A>     our $REGMARK;
^^  A>     my %replacement = qw [X B Y C];
^^  A>     $_ = "AABDAAABBE";
^^  A>     s/(*:X)A(?{})|(*:Y)B/$replacement{$REGMARK}/g;
^^  A>     say;
^^  A>     __END__
^^  A>     BCDBCE
^^  
^^  A> Note that the (?{}) is there to prevent a bug from triggering.
^^  
^^  On Sat, 29 Dec 2007 14:45:17 +0100 "Dr.Ruud" <rvtol+news@isolution.nl> wrote: 
^^  
^^  R> If string-A can ever be a subpattern of string-B, then you need to add a
^^  R> "longest first" approach.
^^  ...
^^  R> (or use a different regex-engine :)
^^  
^^  Abigail's 5.10 solution doesn't scale well, and Dr. Ruud's longest-first

In which sense doesn't it scale well?



Abigail
-- 
:$:=~s:$":Just$&another$&:;$:=~s:
:Perl$"Hacker$&:;chop$:;print$:#:


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

Date: Wed, 02 Jan 2008 08:27:08 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <86fxxg2thf.fsf@lifelogs.com>

On 31 Dec 2007 23:18:23 GMT Abigail <abigail@abigail.be> wrote: 

A> Ted Zlatanov (tzz@lifelogs.com) wrote on VCCXXXV September MCMXCIII in
A> <URL:news:86d4snx8fl.fsf@lifelogs.com>:
A> ^^  On 29 Dec 2007 00:23:55 GMT Abigail <abigail@abigail.be> wrote: 
A> ^^  
A> ^^  A> With 5.10, you can do it with A and B patterns:
A> ^^  
A> ^^  A>     use 5.010;
A> ^^  A>     our $REGMARK;
A> ^^  A>     my %replacement = qw [X B Y C];
A> ^^  A>     $_ = "AABDAAABBE";
A> ^^  A>     s/(*:X)A(?{})|(*:Y)B/$replacement{$REGMARK}/g;
A> ^^  A>     say;
A> ^^  A>     __END__
A> ^^  A>     BCDBCE
A> ^^  
A> ^^  A> Note that the (?{}) is there to prevent a bug from triggering.
A> ^^  
A> ^^  On Sat, 29 Dec 2007 14:45:17 +0100 "Dr.Ruud" <rvtol+news@isolution.nl> wrote: 
A> ^^  
A> ^^  R> If string-A can ever be a subpattern of string-B, then you need to add a
A> ^^  R> "longest first" approach.
A> ^^  ...
A> ^^  R> (or use a different regex-engine :)
A> ^^  
A> ^^  Abigail's 5.10 solution doesn't scale well, and Dr. Ruud's longest-first

A> In which sense doesn't it scale well?

I think it's harder to build the pattern you showed for large numbers of
strings.  Am I wrong?  Sorry if I misunderstood your example.

Ted


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

Date: 02 Jan 2008 15:33:25 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <slrnfnnbm5.i0.abigail@alexandra.abigail.be>

                                         _
Ted Zlatanov (tzz@lifelogs.com) wrote on VCCXXXVII September MCMXCIII in
<URL:news:86fxxg2thf.fsf@lifelogs.com>:
{}  On 31 Dec 2007 23:18:23 GMT Abigail <abigail@abigail.be> wrote: 
{}  
{}  A> Ted Zlatanov (tzz@lifelogs.com) wrote on VCCXXXV September MCMXCIII in
{}  A> <URL:news:86d4snx8fl.fsf@lifelogs.com>:
{}  A> ^^  On 29 Dec 2007 00:23:55 GMT Abigail <abigail@abigail.be> wrote: 
{}  A> ^^  
{}  A> ^^  A> With 5.10, you can do it with A and B patterns:
{}  A> ^^  
{}  A> ^^  A>     use 5.010;
{}  A> ^^  A>     our $REGMARK;
{}  A> ^^  A>     my %replacement = qw [X B Y C];
{}  A> ^^  A>     $_ = "AABDAAABBE";
{}  A> ^^  A>     s/(*:X)A(?{})|(*:Y)B/$replacement{$REGMARK}/g;
{}  A> ^^  A>     say;
{}  A> ^^  A>     __END__
{}  A> ^^  A>     BCDBCE
{}  A> ^^  
{}  A> ^^  A> Note that the (?{}) is there to prevent a bug from triggering.
{}  A> ^^  
{}  A> ^^  On Sat, 29 Dec 2007 14:45:17 +0100 "Dr.Ruud" <rvtol+news@isolution.nl> wrote: 
{}  A> ^^  
{}  A> ^^  R> If string-A can ever be a subpattern of string-B, then you need to add a
{}  A> ^^  R> "longest first" approach.
{}  A> ^^  ...
{}  A> ^^  R> (or use a different regex-engine :)
{}  A> ^^  
{}  A> ^^  Abigail's 5.10 solution doesn't scale well, and Dr. Ruud's longest-first
{}  
{}  A> In which sense doesn't it scale well?
{}  
{}  I think it's harder to build the pattern you showed for large numbers of
{}  strings.  Am I wrong?  Sorry if I misunderstood your example.


"Harder" in the sense of "more typing", yes.

But is there a solution that doesn't require more typing if there
are more strings?



Abigail
-- 
perl -we '$| = 1; $_ = "Just another Perl Hacker\n";  print
          substr  $_ => 0, 1 => "" while $_ && sleep 1 => 1'


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

Date: Wed, 02 Jan 2008 11:05:10 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <86d4sk17ll.fsf@lifelogs.com>

On 02 Jan 2008 15:33:25 GMT Abigail <abigail@abigail.be> wrote: 

A> But is there a solution that doesn't require more typing if there
A> are more strings?

I mean that you can say, with the "simple" approach:

my %reps = ( typing => 'only', goes => 'here', t=>'x');
my @words = sort { length $b <=> length $a } keys %reps;
my $pattern = '(' . join('|', @words) . ')'; # I know I could do it in one step

while(<>)
{
 s/$pattern/$reps{$1}/g;
 print;
}

The only work needed is to populate %reps, but that is more typing with
any approach :)

With yours it's harder to build the match pattern, I think, that's why I
asked you if I'm misunderstanding it.

Ted


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

Date: 02 Jan 2008 17:06:56 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <slrnfnnh5f.i0.abigail@alexandra.abigail.be>

                                         _
Ted Zlatanov (tzz@lifelogs.com) wrote on VCCXXXVII September MCMXCIII in
<URL:news:86d4sk17ll.fsf@lifelogs.com>:
[]  On 02 Jan 2008 15:33:25 GMT Abigail <abigail@abigail.be> wrote: 
[]  
[]  A> But is there a solution that doesn't require more typing if there
[]  A> are more strings?
[]  
[]  I mean that you can say, with the "simple" approach:
[]  
[]  my %reps = ( typing => 'only', goes => 'here', t=>'x');
[]  my @words = sort { length $b <=> length $a } keys %reps;
[]  my $pattern = '(' . join('|', @words) . ')'; # I know I could do it in one step
[]  
[]  while(<>)
[]  {
[]   s/$pattern/$reps{$1}/g;
[]   print;
[]  }
[]  
[]  The only work needed is to populate %reps, but that is more typing with
[]  any approach :)


Yeah, but now you're back to only being able to replace 'fixed strings',
while I posted by approach to be able to deal with patterns.

[]  With yours it's harder to build the match pattern, I think, that's why I
[]  asked you if I'm misunderstanding it.


Sure, it's harder than the "simple approach". But it's more powerful.



Abigail
-- 
perl -we 'eval {die ["Just another Perl Hacker\n"]}; print ${${@}}[$#{@{${@}}}]'


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

Date: Wed, 02 Jan 2008 14:09:10 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <861w900z2x.fsf@lifelogs.com>

On 02 Jan 2008 17:06:56 GMT Abigail <abigail@abigail.be> wrote: 

A> Yeah, but now you're back to only being able to replace 'fixed strings',
A> while I posted by approach to be able to deal with patterns.

That's what I misunderstood.  Thanks for clarifying.

Ted


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

Date: Wed, 2 Jan 2008 09:32:13 -0800 (PST)
From: Babu <sarma.nedunuri@gmail.com>
Subject: split file with according to size
Message-Id: <34bb06e7-6c92-48b4-bfcd-83c1266a138b@d4g2000prg.googlegroups.com>

Hi,

  I have a input file called temp.hex (163840 bytes) . Is there any
function in perl that does the file splitting with size of the file
information

tempA.hex(81920 bytes) and tempB.hex(81920 bytes)
or

tempA.hex(3840 bytes) and tempB.hex(16000bytes)

Thanks in advance

Sn


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

Date: Wed, 2 Jan 2008 09:57:09 -0800 (PST)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: split file with according to size
Message-Id: <e11e23a3-9f53-4e1b-83d5-69a9e4521b6c@c4g2000hsg.googlegroups.com>

On Jan 2, 12:32=A0pm, Babu <sarma.nedun...@gmail.com> wrote:
> Hi,
>
> =A0 I have a input file called temp.hex (163840 bytes) . Is there any
> function in perl that does the file splitting with size of the file
> information
>
> tempA.hex(81920 bytes) and tempB.hex(81920 bytes)
> or
>
> tempA.hex(3840 bytes) and tempB.hex(16000bytes)
>

There's a Unix utility which does this. The name of the utility is,
oddly enough, split.

split -b 81920 <file>



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

Date: Wed, 02 Jan 2008 10:03:19 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: split file with according to size
Message-Id: <K_adnTS9uI12TObanZ2dnUVZ_uidnZ2d@giganews.com>

Babu wrote:

> I have a input file called temp.hex (163840 bytes) . Is there any
> function in perl that does the file splitting with size of the file
> information


Use of "read" is a very direct approach.

Other keyterms for research are, sysread, seek, tell, truncate and eof (end of file).

 From Perl documentation:

***

read FILEHANDLE,SCALAR,LENGTH,OFFSET
read FILEHANDLE,SCALAR,LENGTH

Attempts to read LENGTH characters of data into variable SCALAR
from the specified FILEHANDLE. Returns the number of characters
actually read, 0 at end of file, or undef if there was an error.
SCALAR will be grown or shrunk to the length actually read. If
SCALAR needs growing, the new bytes will be zero bytes. An OFFSET
may be specified to place the read data into some other place in
SCALAR than the beginning. The call is actually implemented in terms
of either Perl's or system's fread() call. To get a true read(2)
system call, see sysread.

Note the characters: depending on the status of the filehandle,
either (8-bit) bytes or characters are read. By default all
filehandles operate on bytes, but for example if the filehandle
has been opened with the :utf8 I/O layer (see open, and the open
pragma, the open manpage), the I/O will operate on characters,
not bytes.

***

Use of "offset" will prove helpful for your task.

You can split apart a hex file but there is no guarantee you
can modify then paste back together a hex file, and have this
file operate correctly, if part of software.

Printing hex data to a file "might" prove problematic. Many
hex characters are outside of a character set "typically"
expected by perl core. This may or may not be a problem
depending on how you handle your data and depending on your
operating system.


This google link will lead you to a lot of reference resources,

http://www.google.com/search?hl=en&q=split+file+hex+perl&btnG=Google+Search


-- 
Purl Gurl
--
So many are stumped by what slips right off the top of my mind
like a man's bad fitting hairpiece.


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

Date: Wed, 02 Jan 2008 19:56:29 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: split file with according to size
Message-Id: <joqnn3tt9mcg2pjunrg5hb6l930hr37rrs@4ax.com>

Babu <sarma.nedunuri@gmail.com> wrote:
>  I have a input file called temp.hex (163840 bytes) . Is there any
>function in perl that does the file splitting with size of the file
>information
>
>tempA.hex(81920 bytes) and tempB.hex(81920 bytes)
>or
>
>tempA.hex(3840 bytes) and tempB.hex(16000bytes)

No, Perl does not have a function with this functionality. It is a rather
special request and it would be odd, if Perl as a general purpose language
would provide a separate function for each and every uncommon file handling
request.
But is trivial to write your own. Just open() the source and target files,
read() as many bytes as you want to go into the first target file, print()
those bytes to the first target file, and then repeat read()ing and
print()ing for the second target file.

However I would just use the external split program instead. Why reinvent
the wheel after all?

jue


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

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


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