RE: Mmodifing Windows registry key

2005-06-22 Thread Nazary, David
Thanks for the suggestion, but here is how I finally ended up doing it
and it does what I needed:

@lic_servers = (nike0,
dhps,
gksc,
fhd6,
FM6S,
);

foreach $lic_serv (@lic_servers)
{   
system (reg add HKLM\\SOFTWARE\\Atria\\ClearCase\\CurrentVersion \/f
\/v LicenseHost \/t REG_SZ \/d \$lic_serv\);
system (get_clearlicense.pl license.txt $lic_serv);
}

David Nazary

-Original Message-
From: Chris Devers [mailto:[EMAIL PROTECTED] 
Sent: Monday, June 20, 2005 11:47 AM
To: Nazary, David
Cc: Perl Beginners - CGI List
Subject: Re: Mmodifing Windows registry key

On Mon, 20 Jun 2005, Nazary, David wrote:

 I want to run a script in a continuous loop so that each time it runs 
 it will modify a registry key and get the data against the new key.
 
 Basically, I need to use reg.exe UPDATE command from inside a perl 
 script. Is it possible?

Yes, but why would you do it that way? Windows Perl provides ways to 
poke at the registry directly, without having to invoke reg.exe by hand.


It would make far more sense to do things with a CPAN module. A quick 
Google / CPAN search suggests that Win32::TieRegistry is the way to go; 
there's an older Win32::Registry, but several sources I found claim that

it is obsolete  Win32::TieRegistry is the best option available now.

http://search.cpan.org/~tyemq/Win32-TieRegistry/TieRegistry.pm
http://www.xav.com/perl/site/lib/Win32/TieRegistry.html

Quoting from ( reformatting) the beginning of the documentation...


SYNOPSIS

  use Win32::TieRegistry 0.20 ( UseOptionName=UseOptionValue[,...]
);
  $Registry-SomeMethodCall(arg1,...);
  $subKey  = $Registry-{Key\\SubKey\\};
  $valueData   =
$Registry-{Key\\SubKeyValueName};
  $Registry-{Key\\SubKey\\} = { NewSubKey = {...} };
  $Registry-{Key\\SubKeyValueName} = NewValueData;
  $Registry-{\\ValueName}   = [ pack(fmt,$data), REG_DATATYPE
];

EXAMPLES

  use Win32::TieRegistry( Delimiter=#, ArrayValues=0 );
  $pound  = $Registry-Delimiter(/);
  $diskKey= $Registry-{LMachine/System/Disk/}
  or die Can't read LMachine/System/Disk key: $^E\n;
  $data   = $key-{/Information}
  or die Can't read LMachine/System/Disk//Information
value: $^E\n;
  $remoteKey  = $Registry-{//ServerA/LMachine/System/}
  or die Can't read //ServerA/LMachine/System/ key:
$^E\n;
  $remoteData = $remoteKey-{Disk//Information}
  or die Can't read ServerA's System/Disk//Information
value: $^E\n;
  foreach $entry (  keys(%$diskKey)  ) {
  ...
  }
  foreach $subKey (  $diskKey-SubKeyNames  ) {
  ...
  }
  $diskKey-AllowSave( 1 );
  $diskKey-RegSaveKey( C:/TEMP/DiskReg, [] );


I'm not a Windows programmer, so I can't vouch for how well this stuff 
work in practice, but it looks pretty straightforward to use. Both 
versions of the documentation linked above provide lots of examples of 
both reading  writing registry keys, so there should be a method that 
maps well to the kind of work that you're doing. 
 
 

-- 
Chris Devers

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




creating html interface for the perl code

2005-06-22 Thread Aditi Gupta
Hi everybody,

I've to create html inteface for a perl code. I've to get the input from the 
user and the data entered in the form has to be processed and output(which 
is a graph) has to be displayed to the user. But i don't know how to do 
it... I am adviced to go for CGI, and i only know basic html.. Please guide 
me.

Thanks in advance,

With Regards,
Aditi


How to handle Null-Charakters

2005-06-22 Thread Angerstein
Hello,

I have a problem reading strings out of a binaery file.

The last 128 Byte of the File contains  a String I want to work with.

(sorry, this code is windows, feel free to flame me ^^)

my $tsize = 128;
my $fsize = (-s d:\\mp3\\forseti.mp3);
my $offset = ($fsize - $tsize);
open(INF, d:\\mp3\\forseti.mp3);
seek(INF, $offset, 0);
$tag = INF;
@id3v1 = split (//, $tag);
$id3v_t =  unpack(B8,$id3v1[125]);
print $id3v_t;

I get:


If I print the whole string it looks like:
This is whatI get   2002
^^   ^^^ ^

The Parts I markt are no whitespaces. They are binaery .

Is there something I could do to transform or remove this null-chars?
(Something small and smart.)

I thought about

$x=0;
foreach @id3v1 ($char){
  $testit = unpack(B8, $char);
  if ($testit =~ m/0{8}/) {
$id3v1[$x] = ;
  }
  $x++;
}

but it this is not very smart or small...


Thanks,

Bastian

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




ssh to a remote machine

2005-06-22 Thread Vijay Kumar Adhikari
Hi,

I need to ssh to a remote machine, run a command and get the output. Is
there some modules that can help.

TIA
Vijay

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.7.10/25 - Release Date: 6/21/2005
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to handle null-chars

2005-06-22 Thread Angerstein
@id3v1 contain 128 Byte Bincode.
to fix 0 Chars I do:
###
$label = cleanup(0,3);

sub cleanup {
 my $jn;
 $start = shift;
 $stop = shift;
 $jn = join(, @id3v1[$start..$stop]);
 $jn =~ s/\0//;
 return $jn;
}
###

Anybody with something better?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




\n ^M

2005-06-22 Thread Dan Klose
Hi everybody,

I have exported an EndNote 7 Library on my Mac to a Bibtex formatted
plain text file.  When I look at the file, rather than having lines
ending with '\n' I seem to have '^M'. I think this is a Mac end of line
problem but the things I have tried don't work and I was wondering if
anyone had any ideas/bits of code to get round this.

Thanks

Dan.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: \n ^M

2005-06-22 Thread Xavier Noria

On Jun 22, 2005, at 11:07, Dan Klose wrote:


Hi everybody,

I have exported an EndNote 7 Library on my Mac to a Bibtex formatted
plain text file.  When I look at the file, rather than having lines
ending with '\n' I seem to have '^M'. I think this is a Mac end of  
line

problem but the things I have tried don't work and I was wondering if
anyone had any ideas/bits of code to get round this.


If there are no \ns then you could do just this:

perl -pi -we 's/\015/\n/g' filename

Note that since $/ is \n the file will be slurped by -p.

-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: ssh to a remote machine

2005-06-22 Thread MNibble

Vijay Kumar Adhikari wrote:

Hi,

I need to ssh to a remote machine, run a command and get the output. Is
there some modules that can help.

TIA
Vijay


Yes there is ..
Net::SSH::Perl

If you ask google Perl Ssh Perl you will get the same answer.

Or you can do something like:
my $output = `ssh [EMAIL PROTECTED] command_to_get_the_output_from`;

with regard
MNibble

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: ssh to a remote machine

2005-06-22 Thread D. J. Birkett

Vijay Kumar Adhikari wrote:

Hi,

I need to ssh to a remote machine, run a command and get the output. Is
there some modules that can help.

TIA
Vijay



You could start here...

http://search.cpan.org/search?query=sshmode=all

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




how to append blocks in same file

2005-06-22 Thread Aditi Gupta
Hi Perlers,

I have a file as follows:

#block1
aaa
aaa

#block2
bbb
bbb

#block3
ccc
ccc

and i want to append(or i should say merge) these blocks and get a file like 
this:

aaabbbccc
aaabbbccc

how can this be done using perl?
please help..

regards
Aditi


cgi link

2005-06-22 Thread Brent Clark

Hi all

 keep getting this message below.

Undefined subroutine main::Link called at C:/Program Files/Apache 
Group/Apache2/cgi-bin/ecco/scripts/common/getXmlAgents.pl line 24.


Here is my code

print $html-header(),

$html-start_html('Get REMOTE BOOKINGS',
-head=Link({-rel='STYLESHEET', -href='/styles/ecco1.css'}),
-bgcolor='white'),

$html-start_form(-method = POST, -action =   ),

Im trying to get a line as such:
LINK REL=STYLESHEET HREF=/styles/ecco1.css TYPE=text/css

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to handle Null-Charakters

2005-06-22 Thread Dave Gray
On 6/22/05, Angerstein [EMAIL PROTECTED] wrote:
 I have a problem reading strings out of a binaery file.
 
 The last 128 Byte of the File contains  a String I want to work with.
 
 (sorry, this code is windows, feel free to flame me ^^)
 
 my $tsize = 128;
 my $fsize = (-s d:\\mp3\\forseti.mp3);
 my $offset = ($fsize - $tsize);
 open(INF, d:\\mp3\\forseti.mp3);
 seek(INF, $offset, 0);
 $tag = INF;
 @id3v1 = split (//, $tag);
 $id3v_t =  unpack(B8,$id3v1[125]);
 print $id3v_t;
 
 I get:
 
 
 If I print the whole string it looks like:
 This is whatI get   2002
 ^^   ^^^ ^
 
 The Parts I markt are no whitespaces. They are binaery .
 
 Is there something I could do to transform or remove this null-chars?

CPAN has modules for working with ID3 tags[1]. That said, you can
replace nulls with a space with:

  $id3v_t =~ s/\0+/ /g;

[1] http://search.cpan.org/search?query=id3mode=all

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: how to append blocks in same file

2005-06-22 Thread Larsen, Errin M HMMA/IT
Aditi Gupta wrote:
 Hi Perlers,
 
 I have a file as follows:
 
 #block1
 aaa
 aaa
 
 #block2
 bbb
 bbb
 
 #block3
 ccc
 ccc
 
 and i want to append(or i should say merge) these blocks and get a
 file like this:
 
 aaabbbccc
 aaabbbccc
 
 how can this be done using perl?
 please help..
 
 regards
 Aditi

Hi,

That looks like a fun and challenging problem.  I bet Perl would be good
at that.

Have you tried any Perl code yet?

This list works best when you present us some code you have tried that
is not working.  Then, we can help you fix it.  There are many on the
list who would be happy to write code for you for a reasonable fee,
however.  Is that what you are looking for?

--Errin

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: cgi link

2005-06-22 Thread Chris Devers
On Wed, 22 Jun 2005, Brent Clark wrote:

 [I'm] trying to get a line as such:
 LINK REL=STYLESHEET HREF=/styles/ecco1.css TYPE=text/css

You're already using CGI.pm, so why not let it do this for you?

http://search.cpan.org/dist/CGI.pm/CGI.pm#LIMITED_SUPPORT_FOR_CASCADING_STYLE_SHEETS

Modifying the code there a bit, this could work:

$newStyle = qq[
!-- 
P.Tip {
margin-right: 50pt;
margin-left:  50pt;
color:red;
}
P.Alert {
font-size:30pt;
font-family:  sans-serif;
color:red;
}
--
]; 

print $cgi-header(),
  $cgi-start_html( -title='CGI with Style',
-style={-src  = '/style/st1.css',
 -code = $newStyle}
   );

Or, to more directly do what you're trying to do, simply adapt the 
section right after the above block:

Any additional arguments passed in the -style value will be 
incorporated into the link tag. For example:

start_html(-style={-src=['/styles/print.css',
   '/styles/layout.css'],
-media = 'all'});

This will give:

link rel=stylesheet type=text/css href=/styles/print.css 
media=all/
link rel=stylesheet type=text/css href=/styles/layout.css 
media=all/

Or if you really want something more customized -- the example you give 
isn't doing anything exotic, so probably not -- then yes you can use the 
$cgi-Link method, but really the CSS-specific stuff is what you need.



-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: creating html interface for the perl code

2005-06-22 Thread Dave Gray
On 6/22/05, Aditi Gupta [EMAIL PROTECTED] wrote:
 I've to create html inteface for a perl code. I've to get the input from the
 user and the data entered in the form has to be processed and output(which
 is a graph) has to be displayed to the user. But i don't know how to do
 it... I am adviced to go for CGI, and i only know basic html.. Please guide
 me.

How about the Template Toolkit[1]? CGI[2] is probably a good starting point.

[1] http://search.cpan.org/~abw/Template-Toolkit-2.14/lib/Template.pm
[2] http://search.cpan.org/~lds/CGI.pm-3.10/CGI.pm

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: creating html interface for the perl code

2005-06-22 Thread Wiggins d'Anconia
Aditi Gupta wrote:
 Hi everybody,
 
 I've to create html inteface for a perl code. I've to get the input from the 
 user and the data entered in the form has to be processed and output(which 
 is a graph) has to be displayed to the user. But i don't know how to do 
 it... I am adviced to go for CGI, and i only know basic html.. Please guide 
 me.
 
 Thanks in advance,
 
 With Regards,
 Aditi
 

You might want to view Ovid's CGI Course:

http://users.easystreet.com/ovid/cgi_course/

It is very popular.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how to append blocks in same file

2005-06-22 Thread Aditi Gupta
Hi all,

I know the terms of the list.. and before this i have always written a code 
and asked for a doubt if it doesn't work... but this time i'm not aware of 
any way to do the job.. thats why i asked to help me out, I haven't asked 
for any code, just hints what can be used. I'm sorry if i gave the wrong 
impression, i was expecting guidelines, not code.

regards,
aditi

On 6/22/05, Larsen, Errin M HMMA/IT [EMAIL PROTECTED] wrote:
 
 Aditi Gupta wrote:
  Hi Perlers,
 
  I have a file as follows:
 
  #block1
  aaa
  aaa
 
  #block2
  bbb
  bbb
 
  #block3
  ccc
  ccc
 
  and i want to append(or i should say merge) these blocks and get a
  file like this:
 
  aaabbbccc
  aaabbbccc
 
  how can this be done using perl?
  please help..
 
  regards
  Aditi
 
 Hi,
 
 That looks like a fun and challenging problem. I bet Perl would be good
 at that.
 
 Have you tried any Perl code yet?
 
 This list works best when you present us some code you have tried that
 is not working. Then, we can help you fix it. There are many on the
 list who would be happy to write code for you for a reasonable fee,
 however. Is that what you are looking for?
 
 --Errin
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 



Re: how to append blocks in same file

2005-06-22 Thread Aditi Gupta
HI Dan,

Since i'm using activestate perl on windows xp i don't know whether paste 
will work or not. 
I'll try the hash of array. 

Thanks for the help

regards
Aditi.

On 6/22/05, Dan Klose [EMAIL PROTECTED] wrote:
 
 If I was doing this I would split the file on the gaps between blocks
 and the use the unix paste function to assemble the blocks.
 
  paste A B C  D
 
 ? using a hash of arrays (HOA) to store each block and then go back over
 the HOA each element at a time ... although this is probably overkill?
 
 On Wed, 2005-06-22 at 09:10 -0500, Larsen, Errin M HMMA/IT wrote:
  Aditi Gupta wrote:
   Hi Perlers,
  
   I have a file as follows:
  
   #block1
   aaa
   aaa
  
   #block2
   bbb
   bbb
  
   #block3
   ccc
   ccc
  
   and i want to append(or i should say merge) these blocks and get a
   file like this:
  
   aaabbbccc
   aaabbbccc
  
   how can this be done using perl?
   please help..
  
   regards
   Aditi
 
  Hi,
 
  That looks like a fun and challenging problem. I bet Perl would be good
  at that.
 
  Have you tried any Perl code yet?
 
  This list works best when you present us some code you have tried that
  is not working. Then, we can help you fix it. There are many on the
  list who would be happy to write code for you for a reasonable fee,
  however. Is that what you are looking for?
 
  --Errin
 
 --
 Daniel Klose
 Mathematical Biology
 NIMR
 The Ridgeway
 Mill Hill
 London
 NW7 1AA
 
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 



RE: How to handle null-chars

2005-06-22 Thread Charles K. Clarkson
Angerstein mailto:[EMAIL PROTECTED] wrote:

: @id3v1 contain 128 Byte Bincode.
: to fix 0 Chars I do:
: ###
: $label = cleanup(0,3);
: 
: sub cleanup {
:  my $jn;
:  $start = shift;
:  $stop = shift;
:  $jn = join(, @id3v1[$start..$stop]);
:  $jn =~ s/\0//;
:  return $jn;
: }
: ###
: 
: Anybody with something better?


First, don't change the name of a thread when you
reply to it.

Second, a subroutine should never act on variables
which were not passed into the sub. @id3v1 hasn't been
passed in.

my $label = id3v1_label( @id3v1[ 0 .. 3 ] );

sub id3v1_label {
my $label = join '', @_;
$label   =~ s/\0//;
return $label;
}


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: ssh to a remote machine

2005-06-22 Thread [EMAIL PROTECTED]
Did you even bother to search CPAN?
http://search.cpan.org/~ivan/Net-SSH-0.08/SSH.pm

Or atleast google in the very least?
http://www.google.com/search?ie=UTF-8oe=UTF-8q=perl+ssh+library

-
Original Message:
From: Vijay Kumar Adhikari [EMAIL PROTECTED]
To: beginners@perl.org
Date: Wednesday, June 22 2005 10:33
Subject: ssh to a remote machine
Hi,

I need to ssh to a remote machine, run a command and get the output. Is
there some modules that can help.

TIA
Vijay

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.7.10/25 - Release Date: 6/21/2005
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: cgi link

2005-06-22 Thread Graeme St.Clair

Try something like:-

$html .= start_html( -title  = Rhubarb,
-style  = { 'src' = '../rhubarb.css' },
-script = [ { 'src' = '../rhubarb.js' },
   $jscript ]
  );

HTH, GStC.

- Original Message - 
From: Brent Clark [EMAIL PROTECTED]

To: Beginners Perl beginners@perl.org
Sent: Wednesday, June 22, 2005 10:00 AM
Subject: cgi link



Hi all

 keep getting this message below.

Undefined subroutine main::Link called at C:/Program Files/Apache 
Group/Apache2/cgi-bin/ecco/scripts/common/getXmlAgents.pl line 24.


Here is my code

print $html-header(),

$html-start_html('Get REMOTE BOOKINGS',
-head=Link({-rel='STYLESHEET', -href='/styles/ecco1.css'}),
-bgcolor='white' ),

$html-start_form(-method = POST, -action =   ),

Im trying to get a line as such:
LINK REL=STYLESHEET HREF=/styles/ecco1.css TYPE=text/css

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how to append blocks in same file

2005-06-22 Thread Dave Gray
On 6/22/05, Aditi Gupta [EMAIL PROTECTED] wrote:
 Since i'm using activestate perl on windows xp i don't know whether paste
 will work or not.
 I'll try the hash of array.

Using a hash of arrays will not necessarily preserve the order. Below
is the start of an array of arrays solution. I'll leave handling
unbalanced blocks and reassembling the pieces as an exercise for the
reader.

my @blocks = ();
my $maxlen = 0;
while (DATA) {
chomp;
if (/^#/) {
push @blocks, [];
} elsif ($_) {
push @{$blocks[$#blocks]}, $_;
my $len = $#{$blocks[$#blocks]};
$maxlen = $len if $len  $maxlen;
}
}

__DATA__
#block1
aaa
ddd

#block2
bbb
eee

#block3
ccc
fff

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Regex Multi-Line Matching

2005-06-22 Thread Jeff Westman
Hey Chris,

I'm not spamming anyone.  I had an error when I sent my email(s) so I
resent it.  Sorry you had to click the mouse an additional time to
'delete'.




Jeff





On 6/20/05, Chris Devers [EMAIL PROTECTED] wrote:
 On Mon, 20 Jun 2005, Jeff Westman wrote:
 
  Any help would be greatly appreciated.
 
 We heard you the first two times.
 
 Please stop spamming the list with the same question.
 
 
 
 --
 Chris Devers


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Syncsave Integers 7Bit Data +1 sync bit... How do I get my value out of it?

2005-06-22 Thread Dave Gray
On 6/22/05, Angerstein [EMAIL PROTECTED] wrote:
 The mp3 format uses something (sick) called syncsave integer.
 
 If you have a 4 Byte 32 Bit the very first bit of every Byte is used
 as a syncsave bit. so you can only put a 28 Bit long Number in it.
 
 Puting stuff in this format is the one thing and getting the right number
 out of it is the other thing I don´t know.
 
 I tried the uucode format transformer unpack(u, $buffer) but this don´t
 work.

What you have to do is skip those ranges (between (2^7)+1 and 2^8, etc).

#!/usr/bin/perl
use strict;
use warnings;

my @data = ((2**8)-1, (2**16)-1, (2**24)-1, (2**32)-1);
my @ss = ();
my %gaps;
for (my $i = 7; $i = 32; $i += 8) {
$gaps{$i} = (2**($i+1)) - (2**$i);
}

# normal to synchsafe
for my $n (@data) {
my $ss = $n;
for my $k (keys %gaps) {
$ss += $gaps{$k} if $ss  (2**$k);
}
print $n - $ss\n;
push @ss, $ss;
}

# synchsafe to normal
for my $ss (@ss) {
my $n = $ss;
for my $k (keys %gaps) {
$n -= $gaps{$k} if $ss  (2**$k);
}
print $ss - $n\n;
}


[1] http://www.id3.org/id3v2.4.0-structure.txt (section 6.2)

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how to append blocks in same file

2005-06-22 Thread Dan Klose

 Using a hash of arrays will not necessarily preserve the order...

If you don't want to worry about sorting the order of the blocks i.e.
doing it yourself then use Tie::IXhash (something like that on CPAN) to
preserve the order, you then don't have to worry about unbalanced blocks
and reassembly by applying an if defined type block. Easy.

Dan

 
 Using a hash of arrays will not necessarily preserve the order. Below
 is the start of an array of arrays solution. I'll leave handling
 unbalanced blocks and reassembling the pieces as an exercise for the
 reader.
 
 my @blocks = ();
 my $maxlen = 0;
 while (DATA) {
 chomp;
 if (/^#/) {
 push @blocks, [];
 } elsif ($_) {
 push @{$blocks[$#blocks]}, $_;
 my $len = $#{$blocks[$#blocks]};
 $maxlen = $len if $len  $maxlen;
 }
 }
 
 __DATA__
 #block1
 aaa
 ddd
 
 #block2
 bbb
 eee
 
 #block3
 ccc
 fff
 
-- 
Daniel Klose
Mathematical Biology
NIMR
The Ridgeway
Mill Hill
London
NW7 1AA


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how to append blocks in same file

2005-06-22 Thread Dave Gray
On 6/22/05, Dan Klose [EMAIL PROTECTED] wrote:
 
  Using a hash of arrays will not necessarily preserve the order...
 
 If you don't want to worry about sorting the order of the blocks i.e.
 doing it yourself then use Tie::IXhash (something like that on CPAN) to
 preserve the order, you then don't have to worry about unbalanced blocks
 and reassembly by applying an if defined type block. Easy.

Almost as easy as giving someone a complete working example to their
homework assignment without them having to learn anything?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




finding needle in a haystack

2005-06-22 Thread Bret Goodfellow
All right, I know how to do this in REXX because there is a word()
function, but how do I do this in Perl.  I want to read in one record at
a time, that has space-delimited fields.  There may be multiple spaces
between the words.  I want to be able to get for example, the 4th word
of the record.  How do I do this?  Just for grins, my record looks like
this:
 
/dev/sun11/lvol13   1032192  377921  613445   38% /techsupp
 
 


Re: finding needle in a haystack

2005-06-22 Thread Chris Devers
On Wed, 22 Jun 2005, Bret Goodfellow wrote:

 All right, I know how to do this in REXX because there is a word()
 function, but how do I do this in Perl. 

The split() function is what you're looking for.

$ perldoc -f split

The perldoc gives this example:

A pattern matching the null string (not to be confused with a
null pattern //, which is just one member of the set of pat-
terns matching a null string) will split the value of EXPR into
separate characters at each point it matches that way.  For
example:

print join(':', split(/ */, 'hi there'));

produces the output 'h:i:t:h:e:r:e'.

It shouldn't be hard to adapt this example to your needs.



-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: finding needle in a haystack

2005-06-22 Thread Ing. Branislav Gerzo
Bret Goodfellow [BG], on Wednesday, June 22, 2005 at 15:11 (-0600)
typed the following:

BG All right, I know how to do this in REXX because there is a word()
BG function, but how do I do this in Perl.  I want to read in one record at
BG a time, that has space-delimited fields.  There may be multiple spaces
BG between the words.  I want to be able to get for example, the 4th word
BG of the record.  How do I do this?  Just for grins, my record looks like
BG this:
 
BG /dev/sun11/lvol13   1032192  377921  613445   38% /techsupp

use regular expressions, for example like this:

use strict;
use warnings;

my $string = '/dev/sun11/lvol13   1032192  377921  613445   38% /techsupp';

# for every word in $string
while ( $string =~ /(\S+\s+)/g ) {
print $1, \n;
}

#get 4th word in string
my ($out) = $string =~ /(?:\S+\s+){3}(\S+)/;
print $out;

__END__

\s - white character (spaces, tabs...)
\S - opposite of \s

-- 

 ...m8s, cu l8r, Brano.

[Confucious say:  Man who smoke pot choke on handle.]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: finding needle in a haystack

2005-06-22 Thread Chris Devers
On Wed, 22 Jun 2005, Ing. Branislav Gerzo wrote:

 Bret Goodfellow [BG], on Wednesday, June 22, 2005 at 15:11 (-0600)
 typed the following:
 
 BG All right, I know how to do this in REXX because there is a word()
 BG function, but how do I do this in Perl.  I want to read in one record at
 BG a time, that has space-delimited fields.  There may be multiple spaces
 BG between the words.  I want to be able to get for example, the 4th word
 BG of the record.  How do I do this?  Just for grins, my record looks like
 BG this:
  
 BG /dev/sun11/lvol13   1032192  377921  613445   38% /techsupp
 
 use regular expressions, for example like this:

No, not like that. A regex in a split will be easier. 

  my $fields = split( /\s+/, $record );
  my $fourth = $fields[3];
 
This problem doesn't require any looping! :-)

 

-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: finding needle in a haystack

2005-06-22 Thread Bret Goodfellow


-Original Message-
From: Chris Devers [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 22, 2005 3:17 PM
To: Bret Goodfellow
Cc: Perl Beginners List
Subject: Re: finding needle in a haystack


On Wed, 22 Jun 2005, Bret Goodfellow wrote:

 All right, I know how to do this in REXX because there is a word() 
 function, but how do I do this in Perl.

The split() function is what you're looking for.

$ perldoc -f split

The perldoc gives this example:

A pattern matching the null string (not to be confused with a
null pattern //, which is just one member of the set of pat-
terns matching a null string) will split the value of EXPR into
separate characters at each point it matches that way.  For
example:

print join(':', split(/ */, 'hi there'));

produces the output 'h:i:t:h:e:r:e'.

It shouldn't be hard to adapt this example to your needs.



-- 
Chris Devers

Thanks Chris,

This is what I actually did to resolve my issue:

@words = split(/ * /, $line)
Print the third word is: $words[2]\n;

Bret Goodfellow



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Critcize my scripts.

2005-06-22 Thread loan tran
Please critize my scripts and suggest better ways to
accomplish the same task. 

(I know it's a good practice to put use strict in Perl
script but I'm struggling to make my scripts work with
use strict.The script below work fine if I comment out
use strict.)

[EMAIL PROTECTED] /home/sybase/scripts/pl =
test_load_lcmr.pl 275 2005 06
Global symbol $isql requires explicit package name
at ././test_load_lcmr.pl line 54.
Global symbol $loader requires explicit package name
at ././test_load_lcmr.pl line 66.
Global symbol $loaderpswd requires explicit package
name at ././test_load_lcmr.pl line 66.
Global symbol $isql requires explicit package name
at ././test_load_lcmr.pl line 78.
Execution of ././test_load_lcmr.pl aborted due to
compilation errors.



 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com
[EMAIL PROTECTED] /home/sybase/scripts/pl = test_load_lcmr.pl 275 2005 06
Global symbol $isql requires explicit package name at ././test_load_lcmr.pl 
line 54.
Global symbol $loader requires explicit package name at ././test_load_lcmr.pl 
line 66.
Global symbol $loaderpswd requires explicit package name at 
././test_load_lcmr.pl line 66.
Global symbol $isql requires explicit package name at ././test_load_lcmr.pl 
line 78.
Execution of ././test_load_lcmr.pl aborted due to compilation errors.

#- script name: test_load_lcmr.pl -- 
#!/usr/bin/perl 
# Purpose: bcp lcmrldr ftp file provided by CPMC into lcmrdb..ldr_stage and 
exec sp to load lcmr
#use strict;
use warnings;
require /home/sybase/scripts/pl/global.pl;
our $recipients = '[EMAIL PROTECTED]';
our $dockdir =/ftpsite/as400/glmgr;
#our $isql = /opt/finance/sybase/OCS-12_0/bin/isql -U$loader -P$loaderpswd 
-w133 ; #now get from global.pl
our $bcp  = '/opt/finance/sybase/OCS-12_0/bin/bcp';
our $company = $ARGV[0];
our $year = $ARGV[1];
our $period = $ARGV[2];
our $server ='THEBRAIN';  # for testing 
our $debug =0;
our $load_file  = 'cpmc_lcmr_'.$year.'_'.$period.'.'.'csv';
our $log_file   = '/home/sybase/scripts/logs/load_lcmr.pl.log';
qx (cp /dev/null $log_file );
#print \nserver = $server; company = $company; Year = $year; period = $period 
\n;
qx(echo server = $server; company = $company; Year = $year; period = $period 
\n $log_file);

# Main Part ##

if($#ARGV != 2 or $company !~ /^\d{3}$/ or $year !~ /^\d{4}$/ or $period !~ 
/^\d{2}$/){
  print \nIncorrect arguments. See usage below:\n;
  Usage;
}
else{
  unless(-f $dockdir/$load_file){die qq(Source file $dockdir/$load_file not 
found. Script aborted.\n); } 
  deleteBeforeLoad($company,$year,$period);
  bcp_in;
  if ($debug ==0){run_lcm2_post($company,$year,$period)} #end if;
  notify_mail;
} #end else

## Sub Routines ###

sub Usage{
 print \n* USAGE ***\n;
 print \n$0 Company Year Period\n;
 print Company: 3 digits required (275)\n;
 print Year   : 4 digits required (2005)\n; 
 print Period : 2 digits required (06)\n; 
 print \n**\n;
 exit;
} #end sub Usage

sub deleteBeforeLoad{
  print ---Delete staging table before bcp in \n;
  qx($isql -S$serverEOF $log_file
select getdate()
go
exec lcmrDB..delete_LDR_Stage $_[0],$_[1],$_[2]
go
EOF
);
check_error;
} #end sub delete

sub bcp_in{
  print ---Start bcp in \n;
  qx($bcp lcmrDB..LDR_Stage in $dockdir/$load_file -c -U$loader -S$server 
-P$loaderpswd -t',' $log_file  );
  my $count_load_file = qx(wc -l $dockdir/$load_file | cut 
-d$dockdir/$load_file -f1 );
  qx(echo \nNumber of rows count from the source file:  $log_file);
  qx(wc -l $dockdir/$load_file  $log_file);
  my $row_copy = qx(egrep rows copied $log_file | cut -drows -f1);
  print \tNumber of rows frm src file = $count_load_file \n;
  print \tNumber of rows bcp in   = $row_copy \n;
  check_error;
}#end bcp_in

sub run_lcm2_post{
  print ---Exec store procedure lcm2_post \n;
  qx($isql -S$serverEOF$log_file
select getdate()
go
--exec lcmrdb..lcm2_post [EMAIL PROTECTED] = $_[0],[EMAIL PROTECTED] = $_[1], 
[EMAIL PROTECTED] = $_[2] 
exec lcmrdb..lcm2_post $_[0],$_[1], $_[2] 
go
select getdate()
go
);
check_error;
}#end sub run

sub check_error{
   my $checkerror =qx(egrep 
Msg|msg|Message|error|Error|ERROR|fail|Unable|unable $log_file);
   if ($checkerror){ $debug +=1; print \tErrors Found here!  \n; }
}#end sub

sub  notify_mail{
  print ---Send notification\n;
  if ($debug ==0){
 print \nLoad completed Succesfully!\n;
 qx(mail -s $0 Completed Successfully $recipients  $log_file); 
  }#end if
  else {
 print \n\t$0 completed with Errors\n;
 qx(mail -s $0 Completed with Errors $recipients  $log_file);
  }#end else
} #end sub



#Script Name global.pl 
#!/usr/local/bin/perl 
#  Global Stuffs
use strict;
use warnings;
our $loader = 'loader';
our $loaderpswd =qx(egrep LOADER /home/sybase/tranl/pl/.sysspec | cut -d= 

anyone knows how to get rid of this error while building CPAN module XML:Smart

2005-06-22 Thread MEENA SELVAM
Hi,
I downloaded, the CPAN module XML:Smart, and used 
perl Makefile.PL
make
make test
in order to build the module (as specified in man
perlmodinstall)and install it in my perl repository. I
am getting the following error:

ok 115
ok 116
ok 117
ok 118
ok 119
ok 120
ok 121
ok 122
ok 123
ok 124
ok 125
ok 126
ok 127
ok 128
ok 129
ok 130
ok 131
ok 132
ok 133
Can't locate object method SWASHNEW via package
utf8 (perhaps you forgot to load utf8?) at
blib/lib/XML/Smart/Data.pm line 258.
make: *** [test_dynamic] Error 2

Should I edit this Data.pm fle to include the
following line at the top?
 
use utf8

should i download utf8? and install as well? what is
meant by loading utf8?

I tried to download and build Test-utf8_0.02 module,
but it fails saying that perl 5.7.3 required, and what
I have is 5.6.1.

Cant I have utf8 or in turn XML:Smart in 5.6.1 version
at all?


meena

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how to append blocks in same file

2005-06-22 Thread Wijaya Edward
 and i want to append(or i should say merge) these blocks and get a 
 file like  this:

 aaabbbccc
 aaabbbccc


I've asked the same question some time ago,
check this out:
http://groups-beta.google.com/group/perl.beginners/browse_thread/thread/4f28012f744d10e0/7638b6eb94a626d2?q=edward+wijaya+group:perl.beginnersrnum=146hl=en#7638b6eb94a626d2

But please make attempt to write your own script first,
no matter how lousy it is. 
Show respect to the time given by people here.

--
Regards,
Edward WIJAYA
Singapore


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Critcize my scripts.

2005-06-22 Thread Wiggins d'Anconia
loan tran wrote:
 Please critize my scripts and suggest better ways to
 accomplish the same task. 


You asked for it.

 (I know it's a good practice to put use strict in Perl
 script but I'm struggling to make my scripts work with
 use strict.The script below work fine if I comment out
 use strict.)
 

Turn on use strict.
Turn on use strict.
Turn on use warnings.
Turn on use strict.

 [EMAIL PROTECTED] /home/sybase/scripts/pl =
 test_load_lcmr.pl 275 2005 06
 Global symbol $isql requires explicit package name
 at ././test_load_lcmr.pl line 54.
 Global symbol $loader requires explicit package name
 at ././test_load_lcmr.pl line 66.
 Global symbol $loaderpswd requires explicit package
 name at ././test_load_lcmr.pl line 66.
 Global symbol $isql requires explicit package name
 at ././test_load_lcmr.pl line 78.
 Execution of ././test_load_lcmr.pl aborted due to
 compilation errors.
 

You are getting these errors because you have not declared all of your
variables. A great place to start:

http://perl.plover.com/FAQs/Namespaces.html

 
 [EMAIL PROTECTED] /home/sybase/scripts/pl = test_load_lcmr.pl 275 2005 06
 Global symbol $isql requires explicit package name at ././test_load_lcmr.pl 
 line 54.
 Global symbol $loader requires explicit package name at 
 ././test_load_lcmr.pl line 66.
 Global symbol $loaderpswd requires explicit package name at 
 ././test_load_lcmr.pl line 66.
 Global symbol $isql requires explicit package name at ././test_load_lcmr.pl 
 line 78.
 Execution of ././test_load_lcmr.pl aborted due to compilation errors.
 
 #- script name: test_load_lcmr.pl -- 
 #!/usr/bin/perl 
 # Purpose: bcp lcmrldr ftp file provided by CPMC into lcmrdb..ldr_stage and 
 exec sp to load lcmr
 #use strict;
 use warnings;
 require /home/sybase/scripts/pl/global.pl;

You might consider making the above dynamic or relative. And 'use' is
often favored to 'require' these days.

perldoc -f use
perldoc lib
perldoc FindBin

 our $recipients = '[EMAIL PROTECTED]';
 our $dockdir =/ftpsite/as400/glmgr;
 #our $isql = /opt/finance/sybase/OCS-12_0/bin/isql -U$loader -P$loaderpswd 
 -w133 ; #now get from global.pl
 our $bcp  = '/opt/finance/sybase/OCS-12_0/bin/bcp';
 our $company = $ARGV[0];
 our $year = $ARGV[1];
 our $period = $ARGV[2];

You might try using Getopt::Long for option processing. I have a sample
template available at:

http://danconia.org/cgi-bin/request?handler=Content;content=StaticPage;label=getopt_long_template

 our $server ='THEBRAIN';  # for testing 
 our $debug =0;
 our $load_file  = 'cpmc_lcmr_'.$year.'_'.$period.'.'.'csv';
 our $log_file   = '/home/sybase/scripts/logs/load_lcmr.pl.log';
 qx (cp /dev/null $log_file );

You shouldn't shell out for the above process which appears to just
empty a file. You can use Perl builtins for that, and should. When
copying a file you should consider using File::Copy.

 #print \nserver = $server; company = $company; Year = $year; period = 
 $period \n;
 qx(echo server = $server; company = $company; Year = $year; period = $period 
 \n $log_file);
 

There is no reason to shell out to echo, print should work fine. Why the
commented out line above? If you are trying to write to the log file,
you should open it for printing.

perldoc perlopentut
perldoc -f open
perldoc -f print
perldoc -f close

 # Main Part ##
 
 if($#ARGV != 2 or $company !~ /^\d{3}$/ or $year !~ /^\d{4}$/ or $period !~ 
 /^\d{2}$/){
   print \nIncorrect arguments. See usage below:\n;
   Usage;

Using  is the older method, the above is better written:

usage();

But see my template on a nice way to handle option processing, usage
statements, and documentation all rolled into one.

 }
 else{
   unless(-f $dockdir/$load_file){die qq(Source file $dockdir/$load_file 
 not found. Script aborted.\n); } 
   deleteBeforeLoad($company,$year,$period);

Again, no ''.


   bcp_in;

Same, the above should take its arguments and optionally return
value(s). You are using globals in your subroutines which is evil,
strict will help, as will moving your subs into a library.

   if ($debug ==0){run_lcm2_post($company,$year,$period)} #end if;
   notify_mail;
 } #end else
 
 ## Sub Routines ###
 
 sub Usage{
  print \n* USAGE ***\n;
  print \n$0 Company Year Period\n;
  print Company: 3 digits required (275)\n;
  print Year   : 4 digits required (2005)\n; 
  print Period : 2 digits required (06)\n; 
  print \n**\n;
  exit;
 } #end sub Usage
 
 sub deleteBeforeLoad{
   print ---Delete staging table before bcp in \n;
   qx($isql -S$serverEOF $log_file

You might consider using the DBI module and its drivers depending on
what database this is.

 select getdate()
 go
 exec lcmrDB..delete_LDR_Stage $_[0],$_[1],$_[2]
 go
 EOF
 );
 check_error;
 } #end sub delete
 
 sub bcp_in{
   print ---Start bcp in \n;
   qx($bcp lcmrDB..LDR_Stage in $dockdir/$load_file -c -U$loader -S$server 
 -P$loaderpswd -t',' $log_file  );


cant locate SF:Logger.pm in @INC: how to add additional paths in @INCHi,

2005-06-22 Thread MEENA SELVAM
 
 



__ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




how to add additional paths in $INC( can't locate SF:Logger.pm in $INC)

2005-06-22 Thread MEENA SELVAM
My perl program snas.pl uses SF:Logger.pm which is
available in /usr/local/sf/lib/perl/5.8.3/SF. I have
added this directory in the path (.cshrc and .tshrc).
I am running as root, and I get the cant locate
SF::Logger.pm error in $INC.

$INC contains usr/lib/perl5/5.6.1/i386_linux and some
more usr/lib/perl5/... directories

How can i alter this $INC. I tried using 
use lib /usr/local/sf/lib/perl/5.8.3/SF; since I
found that this should work as per perl.apache.org
perl reference document.

meena



 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how to add additional paths in $INC( can't locate SF:Logger.pm in $INC)

2005-06-22 Thread Wiggins d'Anconia
MEENA SELVAM wrote:
 My perl program snas.pl uses SF:Logger.pm which is
 available in /usr/local/sf/lib/perl/5.8.3/SF. I have
 added this directory in the path (.cshrc and .tshrc).
 I am running as root, and I get the cant locate
 SF::Logger.pm error in $INC.
 
 $INC contains usr/lib/perl5/5.6.1/i386_linux and some
 more usr/lib/perl5/... directories
 
 How can i alter this $INC. I tried using 
 use lib /usr/local/sf/lib/perl/5.8.3/SF; since I
 found that this should work as per perl.apache.org
 perl reference document.
 
 meena
 

If the module you are using is SF::Logger then the path you need to add
is like the above only without the 'SF', perl will add that
automagically. Try,

use lib /usr/local/sf/lib/perl/5.8.3;

Alternatively, Perl doesn't use the $PATH shell environment variable, it
used $PERL5LIB instead. In bash for instance,

export PERL5LIB=$PERL5LIB:/usr/local/sf/lib/perl/5.8.3

Should do the trick

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to handle Null-Charakters

2005-06-22 Thread John W. Krahn

Angerstein wrote:

Hello,


Hello,


I have a problem reading strings out of a binaery file.


perldoc -f binmode



The last 128 Byte of the File contains  a String I want to work with.

(sorry, this code is windows, feel free to flame me ^^)

my $tsize = 128;
my $fsize = (-s d:\\mp3\\forseti.mp3);
my $offset = ($fsize - $tsize);
open(INF, d:\\mp3\\forseti.mp3);
seek(INF, $offset, 0);
$tag = INF;


I would write that as:

use Fcntl ':seek';

my $tsize = 128;
my $file  = 'd:/mp3/forseti.mp3';
open INF, '', $fileor die Cannot open $file: $!;
binmode INF;
seek INF, -$tsize, SEEK_END or die Cannot seek $file: $!;
read INF, my $tag, $tsize   or die Cannot read $file: $!;



@id3v1 = split (//, $tag);
$id3v_t =  unpack(B8,$id3v1[125]);


Do you really need to split() $tag?

my $id3v_t =  unpack 'B8', substr $tag, 125, 1;



print $id3v_t;

I get:






If I print the whole string it looks like:
This is whatI get   2002
^^   ^^^ ^

The Parts I markt are no whitespaces. They are binaery .

Is there something I could do to transform or remove this null-chars?
(Something small and smart.)


$tag =~ tr/\0/ /s;



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response