Compressed data embedded in script

2009-10-04 Thread Bryan Harris



I have about 60 MB of text data I want to include at the bottom of a script.

60 MB is too big for us, but compressed it would be probably only 3-6 MB
which is much better.  Is there any way to put gzipped data in the DATA
section of a script, and conveniently read it?

I'd also prefer that my script be able to survive getting passed through a
terminal -- is it hard to encode the data block (MIME perhaps?) so it will?

TIA!

- Bryan




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Change character code 160 to 32

2009-10-04 Thread Mike Flannigan


I want to change character code 160 to character
code 32 throughout a bunch of text files.  I'm using
this right now
s/(.)/ord($1) == '160' ? chr(32) : $1 /eg;
and it works, but I don't like it much.  If anybody
has another way they like better, I'd appreciate
seeing it.  It does not have to be a reg exp.

Anybody know why this doesn't work?
tr/\160/\32/d;
Oddly it replaces 'p' (character code 80) with
character code 26???

I get the digest version, so may not respond
right away.


Mike Flannigan


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Change character code 160 to 32

2009-10-04 Thread Shawn H Corey
Mike Flannigan wrote:
 
 I want to change character code 160 to character
 code 32 throughout a bunch of text files.  I'm using
 this right now
 s/(.)/ord($1) == '160' ? chr(32) : $1 /eg;
 and it works, but I don't like it much.  If anybody
 has another way they like better, I'd appreciate
 seeing it.  It does not have to be a reg exp.
 
 Anybody know why this doesn't work?
 tr/\160/\32/d;
 Oddly it replaces 'p' (character code 80) with
 character code 26???
 
 I get the digest version, so may not respond
 right away.
 
 
 Mike Flannigan
 
 

Use the hex notation:

perl -i -ple 'tr/\xA0/\x20/' files


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Compressed data embedded in script

2009-10-04 Thread Uri Guttman
 BH == Bryan Harris bryansli...@gmail.com writes:

  BH I have about 60 MB of text data I want to include at the bottom of
  BH a script.

  BH 60 MB is too big for us, but compressed it would be probably only
  BH 3-6 MB which is much better.  Is there any way to put gzipped data
  BH in the DATA section of a script, and conveniently read it?

  BH I'd also prefer that my script be able to survive getting passed
  BH through a terminal -- is it hard to encode the data block (MIME
  BH perhaps?) so it will?

not details but a couple of suggestions. there are several compress
modules in cpan and i would guess some can take a string arg. if they
can't you can still open a string (see perldoc perlopentut) as a file
handle. so that solves the uncompress part. you can store the data
encoded with B64 in the DATA part of a module/script (after __DATA__) or
in a here doc. get it and decode it with a B64 or some other decoder (i
think unpack/pack as uuencode support too). then uncompress. this should
be all of about 3-5 lines of code in total.

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Change character code 160 to 32

2009-10-04 Thread Shlomi Fish
On Sunday 04 Oct 2009 17:53:24 Mike Flannigan wrote:
 I want to change character code 160 to character
 code 32 throughout a bunch of text files.  I'm using
 this right now
 s/(.)/ord($1) == '160' ? chr(32) : $1 /eg;
 and it works, but I don't like it much.  If anybody
 has another way they like better, I'd appreciate
 seeing it.  It does not have to be a reg exp.
 
 Anybody know why this doesn't work?
 tr/\160/\32/d;
 Oddly it replaces 'p' (character code 80) with
 character code 26???
 

Well, Shawn gave you the correct answer, I'll just explain why it didn't work 
for you. The reason it doesn't is because \DDD uses octal digits - not decimal 
ones:

http://en.wikipedia.org/wiki/Octal

Regards,

Shlomi Fish

 I get the digest version, so may not respond
 right away.
 
 
 Mike Flannigan
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Change character code 160 to 32

2009-10-04 Thread John W. Krahn

Mike Flannigan wrote:


I want to change character code 160 to character
code 32 throughout a bunch of text files.  I'm using
this right now
s/(.)/ord($1) == '160' ? chr(32) : $1 /eg;


Here you are using the decimal numbers 160 and 32.  This is very 
inefficient as you are searching for *every* character (except newline) 
and replacing every character.  It would be much simpler and more 
efficient to just search for the character you want and replace only 
that character:


my $search  = quotemeta chr 160;
my $replace = chr 32;

s/$search/$replace/g;



and it works, but I don't like it much.  If anybody
has another way they like better, I'd appreciate
seeing it.  It does not have to be a reg exp.

Anybody know why this doesn't work?
tr/\160/\32/d;
Oddly it replaces 'p' (character code 80) with
character code 26???


The escape sequences you are using are octal (not decimal) 
representations of the ordinal values of the characters.  You have to 
convert the decimal values 160 and 32 to the octal values 240 and 40.


$ perl -le'printf %d decimal = %o octal and %d decimal = %o octal\n, 
160, 160, 32, 32'

160 decimal = 240 octal and 32 decimal = 40 octal

So it then becomes:

tr/\240/\40/;

(You do not need the /d option as you are not deleting any characters.)

Or using substitution:

s/\240/\40/g;




John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.   -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Tips and Tricks?

2009-10-04 Thread Slick
I am new at this perl thing. I just want to know tips and simple scripting.  I 
also use strawberry perl for my program. 

Thanks

 Jason H. Owens



  

Re: Tips and Tricks?

2009-10-04 Thread rodrick brown
The builtun module Data::Dumper is very essential when working with  
data complez structures.


Use strict is very useful for catching programming and user errors

Sent from my iPhone 3GS.

On Oct 4, 2009, at 2:02 PM, Slick jho251...@yahoo.com wrote:

I am new at this perl thing. I just want to know tips and simple  
scripting.  I also use strawberry perl for my program.


Thanks

Jason H. Owens





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Tips and Tricks?

2009-10-04 Thread Shawn H Corey
Slick wrote:
 I am new at this perl thing. I just want to know tips and simple scripting.  
 I also use strawberry perl for my program. 

1. Create a folder for trying Perl:  md C:\TRY
(In Linux: mkdir ~/try )

2. Create a file in your try folder called template.pl and load the
following in it.  When you want a new Perl script, copy it to the new name.

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
$Data::Dumper::Maxdepth = 0;

# place new code here

__END__


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Tips and Tricks?

2009-10-04 Thread Shlomi Fish
Hi Slick!

On Sunday 04 Oct 2009 20:02:36 Slick wrote:
 I am new at this perl thing. I just want to know tips and simple scripting.
   I also use strawberry perl for my program.
 

Strawberry Perl is a very fine choice for Perl on Windows - probably better 
than ActivePerl by now.

For a comprehensive site with many links to beginner-friendly Perl resources 
see:

http://perl-begin.org/

(Note: I've originated this site and am still its primary maintainer).

We're currently working on integrating the good stuff from there and other 
sites into the various *.perl.org sites, but that is an ongoing process that 
will take some time.

Regards,

Shlomi Fish

 Thanks
 
  Jason H. Owens
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Change character code 160 to 32

2009-10-04 Thread Mike Flannigan


Shawn H Corey wrote:

Use the hex notation:

perl -i -ple 'tr/\xA0/\x20/' files
  


Thank you.  Much appreciated.  I do like
that much better.

Someday I'll know hexidecimal better.  Right
now it's got a little magic for me.


Mike


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Tips and Tricks?

2009-10-04 Thread Shawn H Corey
Shlomi Fish wrote:
 For a comprehensive site with many links to beginner-friendly Perl resources 
 see:
 
 http://perl-begin.org/

Another on-line resource: http://perldoc.perl.org/

perldoc is an executable that comes with Perl and displays Perl
dicumentation.  In a command prompt, type: perldoc perl

This gives you a table of contents of the perldoc's.  The above link is
the documentation but in searchable format.

Also, `perldoc perlmodlib` gives a list of all Perl modules and
pragmatics that should come with Perl (some distributions are beginning
NOT to include them all).  You can read about them with `perldoc
module_or_pragmatic_name`.  Or you can search for them at perldoc.perl.org


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Change character code 160 to 32

2009-10-04 Thread Shawn H Corey
Mike Flannigan wrote:
 
 Shawn H Corey wrote:
 Use the hex notation:

 perl -i -ple 'tr/\xA0/\x20/' files
   
 
 Thank you.  Much appreciated.  I do like
 that much better.
 
 Someday I'll know hexidecimal better.  Right
 now it's got a little magic for me.
 
 
 Mike

If you're on Linux, type: man ascii

Else see: http://en.wikipedia.org/wiki/ASCII


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Tips and Tricks?

2009-10-04 Thread Robert H

On 10/4/09 2:51 PM, Shlomi Fish wrote:

Hi Slick!

On Sunday 04 Oct 2009 20:02:36 Slick wrote:

I am new at this perl thing. I just want to know tips and simple scripting.
   I also use strawberry perl for my program.



Strawberry Perl is a very fine choice for Perl on Windows - probably better
than ActivePerl by now.



Better in what way?

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Perl Questions

2009-10-04 Thread Slick
I have a couple of questions.  

What is a good starter perl book to learn perl.

Secondly, I am kinda having trouble assimilating all the perl information.  I 
want to know ways that you all remember the format of a script as well as the 
main items that are normally use.  I know about the Scalars (word for a word 
with $ used.  $a=2), Array (several items @b= (1, 2, 3).  I am just having 
problems figuring out when and where they would be used and to a point reading 
a script.  

Hope you don't mind my questions.  Just trying to compliment my A+ skills, 
trying to be a IT tech and that would help for system administration (how I 
don't know yet, cause I am still learning)

 Jason H. Owens



  

Re: Tips and Tricks?

2009-10-04 Thread Shawn H Corey
Slick wrote:
 I tried that, and the programs I am using worked before I put my code
 where the code needed to be, but it did not run.  However if did the
 code without that template it worked. 
  
 Jason H. Owens

I'm sorry.  My mother tongue is English.  I do not understand what you
are saying.  Please include beginners@perl.org when you reply.  You can
do this with 'Reply All'


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Questions

2009-10-04 Thread Shawn H Corey
Slick wrote:
 I have a couple of questions.  
 
 What is a good starter perl book to learn perl.
 
 Secondly, I am kinda having trouble assimilating all the perl information.  I 
 want to know ways that you all remember the format of a script as well as the 
 main items that are normally use.  I know about the Scalars (word for a word 
 with $ used.  $a=2), Array (several items @b= (1, 2, 3).  I am just having 
 problems figuring out when and where they would be used and to a point 
 reading a script.  

Remembering comes with practise.  And remembering that if you have a
difficult task to do, somebody else has done it before.  See
http:///search.cpan.org/


 
 Hope you don't mind my questions.  Just trying to compliment my A+ skills, 
 trying to be a IT tech and that would help for system administration (how I 
 don't know yet, cause I am still learning)

Don't mind questions.  (Do mind replies without thought.  Leads to
argument beyond the original question.  Search Google for Burnt Camel
Club :)


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Questions

2009-10-04 Thread Tim Bowden
On Sun, 2009-10-04 at 15:03 -0700, Slick wrote:
 I have a couple of questions.  
 
 What is a good starter perl book to learn perl.

Best learning Perl book is 'Learning Perl'.  Also known as the Lama
book.  There are other good texts also, but imho that is by far the
best.

 
 Secondly, I am kinda having trouble assimilating all the perl
  information.  I want to know ways that you all remember the format of
  a script as well as the main items that are normally use.  I know
  about the Scalars (word for a word with $ used.  $a=2), Array (several
  items @b= (1, 2, 3).  I am just having problems figuring out when and
  where they would be used and to a point reading a script.  

I once read that Perl was written to be programmer friendly, not learner
friendly, and that the best way to learn Perl is to use it every day for
at least 20 mins.  Come to think of it, that advice may well have come
from the Lama book.

 
 Hope you don't mind my questions.  Just trying to compliment my A+
  skills, trying to be a IT tech and that would help for system
  administration (how I don't know yet, cause I am still learning)

No idea how much Perl is used in Windows admin, but I'd hate to admin a
nix box without any Perl skills.

 
  Jason H. Owens
 

Tim Bowden


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/