[27354] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9056 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 15 21:05:46 2006

Date: Wed, 15 Mar 2006 18:05:05 -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           Wed, 15 Mar 2006     Volume: 10 Number: 9056

Today's topics:
    Re: Accessing package data through variable <a-brahme@ti.com>
    Re: Can I skip tokens in RegExp backreferences? <matthew.garrish@sympatico.ca>
    Re: Can I skip tokens in RegExp backreferences? <matthew.garrish@sympatico.ca>
    Re: Can I skip tokens in RegExp backreferences? <matthew.garrish@sympatico.ca>
        help with one liners <kelly@filc9273.fm.intel.com>
    Re: help with one liners <xx087@freenet.carleton.ca>
    Re: manipulating JPEG images robic0
        Using a variable to call a sub-routine... <jbredice@hotmail.com>
    Re: Using a variable to call a sub-routine... <1usa@llenroc.ude.invalid>
    Re: Using a variable to call a sub-routine... <jbredice@hotmail.com>
    Re: Using a variable to call a sub-routine... <matthew.garrish@sympatico.ca>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 16 Mar 2006 07:09:25 +0530
From: Amit Brahme <a-brahme@ti.com>
Subject: Re: Accessing package data through variable
Message-Id: <dvafke$ba7$1@home.itg.ti.com>

Thanks Tad.

I've sent reply to Paul about reason why I was trying to do this. If you 
can help me with a better way to handle this please do so.

Thanks and regards
Amit

Tad McClellan wrote:

> Amit Brahme <a-brahme@ti.com> wrote:
> 
> 
>>	I want to know if perl can do following thing.
> 
> 
> 
> It can, but doing the following is a really really bad idea...
> 
> 
> 
>>------------------------------------------------------------------------
>>I've a package and some variables defined in it, like below, in file 
>>lets say "junk1.pm".
>>
>>******************
>>package junk1;
>>$foo = "xyz";
>>$abc = "123";
>>******************
>>
>>In my program I write a code like
>>
>>******************
>>require "junk1.pm";
>>$myrf = "junk1";
>>print $junk1::foo;
>>******************
>>
>>
>>What I want is: instead of using
>>
>>print $junk1::foo;
>>
>>I want to use $myrf (which is defined as "junk1") to access variable 
>>"foo" in package junk1.
> 
> 
> 
> Why do you want to use $myrf to access variable "foo" in package junk1?
> 
> What is wrong with using $junk1::foo instead?
> 
> If we knew what real problem you are trying to solve, we may be
> able to help solve it...
> 
> 
> You are trying to use "symbolic references", which can lead
> to extremely hard-to-find bugs.
> 
> There is almost always a better way to accomplish what you need
> without symrefs, but we would need to know what you are really
> trying to accomplish.
> 
> 
> 
>>I tried
>>
>>print ${$myrf}::foo;
>>
>>but perl gives error for this that it found barework foo. Is there any 
>>way I can do something like this?
> 
> 
> 
>    print ${$myrf . '::foo'}   # don't do this!
> 
> or
> 
>    print ${"${myrf}::foo"}  # don't do this either!
> 
> 


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

Date: Wed, 15 Mar 2006 17:38:42 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Can I skip tokens in RegExp backreferences?
Message-Id: <IH0Sf.3575$fy1.205252@news20.bellglobal.com>


"Someone Else" <invalid@earthlink.net.invalid> wrote in message 
news:cSJRf.4199$sL2.327@newsread2.news.atl.earthlink.net...
> What I want to do is to use a regular expression like:
>
>     /([+-]\s*\d+)/;
>
> to parse some fairly complicated algebraic expressions; but I don't want 
> to capture the \s* as part of $1. In other words, I would like either "+ 
> 32" or "+32" to store "+32" in $1. (I've extracted the salient feature. 
> The real problem is much more complicated, but the details are essentially 
> irrelevant to my question. See below if you're interested.)
>
> What I am looking for is something like:
>
>     /([+-](?:\s*)\d+)/;
>
> but not quite. Not only don't I want to capture the \s* in $2, but I want 
> to exclude it from the enclosing $1.
>
> Any ideas?
>

I'm sure by now you know it's not, but being one to abuse the /e modifier 
for the sake of cramming everything into one line:

my $num = '-  2123 + 1234';
$num =~ s#([+-]\s*\d+)#(my $temp=$1)=~tr/ //d;$temp#ge;
print $num;

Of course, you aren't going to gain anything but a headache for not writing 
it all out...

Matt 




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

Date: Wed, 15 Mar 2006 18:17:25 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Can I skip tokens in RegExp backreferences?
Message-Id: <_f1Sf.3582$fy1.207556@news20.bellglobal.com>


<robic0> wrote in message news:960f1218rhde9h9gus6d1s3d7n8tj5io4u@4ax.com...
> On Wed, 15 Mar 2006 01:12:40 GMT, Someone Else 
> <invalid@earthlink.net.invalid> wrote:
>
>>What I want to do is to use a regular expression like:
>>
>>     /([+-]\s*\d+)/;
>>
>>to parse some fairly complicated algebraic expressions; but I
>>don't want to capture the \s* as part of $1. In other words, I
>>would like either "+ 32" or "+32" to store "+32" in $1. (I've
>>extracted the salient feature. The real problem is much more
>>complicated, but the details are essentially irrelevant to my
>>question. See below if you're interested.)
>>
>>What I am looking for is something like:
>>
>>     /([+-](?:\s*)\d+)/;
>>
>>but not quite. Not only don't I want to capture the \s* in $2,
>>but I want to exclude it from the enclosing $1.
>>
>>Any ideas?
>>
>>Semi-irrelevant details follow:
>>
>>In the simple example above it's easy to ignore $2. The real
>>application is more like:
>>
>>     @a = /\s*([+-]\s*\d+)/g;
>>
>>In that case it's still easy to use:
>>
>>     @a = /\s*([+-])\s*(\d+)/g;
>>
>>and then concatenate every pair of entries in @a. But as I said,
>>the real application is much more complicated. It involves
>>parsing 40 MB files written in an arcane linear programming
>>language, with floating-point coefficients, variable names that
>>can include nearly any printable character, extending over many
>>lines, interspersed with relational symbols, etc.. So I'd really
>>like to avoid a lot of pre- or post-processing.
>>
>
> if ($var ~= s/([+-]*?)\s*?(\d+?)/$1$2/) {

What is \s*? to you? And the difference between it and \s* in this context 
is?

The point of a non-greedy modifier is to limit how far the match will 
extend. In this case, you have three *distinct patterns* involved, none of 
which overlap or would be affected by adding the non-greedy "*?". The [+-] 
character class will stop matching when it hits anything that is not one of 
those two characters, and \s and \d are not. Likewise, the \s whitespace 
will stop matching when it hits anything that is not whitespace. And the 
last \d+? does what, as it's not anchored to anything?

Try and follow:

my $num = '    1234';

If you wanted to write a regex that grabs the group of numbers, but excludes 
4 if it's at the end (as it is above), you wouldn't write:

$num =~ s/^\s*(\d+)4?$/$1/g;

because the \d+ will grab the four, as it's optional outside the capture. 
Instead you'd write:

$num =~ s/^\s*(\d+?)4?$/$1/g;

In this case, \d+? will not capture the four, even though the four is a 
digit, because you just made it non-greedy (i.e., you allow what follows the 
capture to match).

Please take the time to learn about what you profess to know before making 
us all painfully aware yet again that you don't.

>   print "found: $var\n";
> else {
>   print "no match found: $var\n";
> }
>
> But you bettern need to know what text you will be dealing with.
> To include \s*, zero or more white spaces, indicates that you
> can't guarantee the [+-] character class nor the numbers.

Does that mean something in English, or just in your head?

Matt 




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

Date: Wed, 15 Mar 2006 18:21:33 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Can I skip tokens in RegExp backreferences?
Message-Id: <Sj1Sf.3585$fy1.207984@news20.bellglobal.com>


"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message 
news:_f1Sf.3582$fy1.207556@news20.bellglobal.com...
>
> my $num = '    1234';

>
> $num =~ s/^\s*(\d+)4?$/$1/g;
>

> $num =~ s/^\s*(\d+?)4?$/$1/g;
>

Shouldn't have recycled an old script. No point in the /g modifiers being in 
there...

Matt 




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

Date: 15 Mar 2006 13:19:09 -0800
From: Michael Kelly - PCD ~ <kelly@filc9273.fm.intel.com>
Subject: help with one liners
Message-Id: <us2wtevv22a.fsf@filc9273.fm.intel.com>

Is there a good doc or tutorial source on the web for PERL oneliners?
especially oneliners inside  vim?
I especially want to split on commas, and swap $_[55] = $_[61]
as using @F=split(",") ; s/$F[55]/$F[61]/
does not work if $F[1] matches $F[55].
-- 
I don't speak for Intel
Michael Kelly (the one in Folsom)
"and nobody is fooled except the usual fools."
--Jonah Goldberg


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

Date: 15 Mar 2006 21:37:24 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: help with one liners
Message-Id: <slrne1h28l.dig.xx087@smeagol.ncf.ca>

At 2006-03-15 04:19PM, Michael Kelly - PCD ~ <kelly@filc9273.fm.intel.com> wrote:
>  Is there a good doc or tutorial source on the web for PERL oneliners?
>  especially oneliners inside  vim?
>  I especially want to split on commas, and swap $_[55] = $_[61]
>  as using @F=split(",") ; s/$F[55]/$F[61]/
>  does not work if $F[1] matches $F[55].

Perl is not confined to regular expressions alone:

    @a = (1,2,3,4,5);
    @a[0,-1] = @a[-1,0];    # swap first and last fields
    print join(',', @a);    # ==> 5,2,3,4,1

As a oneliner, I'd write:
    
    perl -F, -ane '@F[55,61]=@F[61,55]; print join(',',@F),"\n"'

not sure if the trailing newline is required.

-- 
Glenn Jackman
Ulterior Designer


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

Date: Wed, 15 Mar 2006 16:41:18 -0800
From: robic0
Subject: Re: manipulating JPEG images
Message-Id: <hb9h12dql86hkt71i8p6dq8vf41eb8bub0@4ax.com>

On Tue, 14 Mar 2006 19:07:43 -0800, "Murray R. Van Luyn" <vanluynm@NOSPAM.iinet.net.au> wrote:

>For an assignment I'm required to find out how to remove camera shake from 
>JPEG images using Perl.
>
>I'm stumped! I'm not after a solution, but would really appreciate direction 
>to sources of information that may help me to figure out how to accomplish 
>this task.
>
>Regards,
>Murray R. Van Luyn. 
>
Just a followup, mpegs are composed of many thousands, if not millions of frames
depending on how big it is, which I'm sure you know. I wouldn't imagine those frames
just lying around on a hardisk in the un-compressed state.

You can't just "edit" bitmap images and remake the mpeg video. Its a process that has
to be done on the fly. Each frame is decompressed, then altered, then recompressed
into a new video. In that process, it loses bit information and degrades in quality.
As each frame is decompressed in the stream, it can be altered, then sent to a 
compressor like CCE (CinemaCraft Encoder or a couple of others).
CCE costs around $2,000 for a license. Or you could purchace a license for a copy
of the mpeg2 specifications for around $3,000 and write your own encoder in Perl.

There are not really 30 fps stored in the mpeg. An algo is used that just
stores the difference binary between frames (back to the I-Frame). When the difference
passes the size of a full frame threshold, a new datum, called an I-Frame is inserted,
then the process repeats. Of course this is in general as sub D-Frames are factored
out as well as other optimizations.
When a frame (image) is to be reconstituted (decompressed), it's formed from several
binary regions in the I-Frame grouping. In general, the difference binary goes through
an encoding so decoding will produce the image that was encoded, mostly for viewing.
Encoding then decoding will not produce the exact same image that was originally encoded.

There are many utilities on "Doom9.org" that can help you to filter streaming frames (images).
The folks that write them are real genius types. All these are proofs. By that I mean
its a pure software solution, but could easily be ported to realtime video specific
hardware/firmware, and I'm sure they are. Doom9 will give you the poor man's solution to
big time video production. Even though its shareware, its fairly complex and arcane for
beginners.

Fully uncompressed images from a 2-hour mpeg2 medium-high bitrate, 2 hour, quality movie, will 
generate about 300-500 gigabytes of data on a harddrive. For that reason, image processing is
usually done on the frame level, then that frame is fed to the encoder. I'm not saying those
500 gigs of images can't be fed to the encoder, but its just not done that way, usually.

The methods used usually include a decompressor prgram (with an available codec) as a first
step. Dvd2Svcd is a good choice for this but not necessary. 

Next is the heart of video processing, a program like AviSynth, which is a frameserver but
more important, a program that knows how to use plug-in filters, that modify the frames
(individually or in groups). This is where a possible jitter removal algo is used.
Filtering here is very complicated. Anything that can be done with any paint program,
stretching, gamma, sharp, contrast, brightnes, dubbing, overlays, to name a few.
There are hundreds of filters available. These are incredibly complex algols. They are 
written entirely in assembly and is the heard of video editing/processing occurs.

After each frame (or series of frames) has run through AviSynth, it is sent on to the encoder.
CCE or TmpgEnc where it is packed into mpeg2 format (I-Frames and all). 

AviSynth is a "master" program that coordinates this process. It is script driven, as with
most of these programs.

Don't worry about jitter removal. The assembly to do the simplest of filters on a single frame
is something you could not understand.

Doom9.org is your best bet, unless you think anybody here, or Perl could help you..
Hey, anythings possible I guess!!

good luck


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

Date: Wed, 15 Mar 2006 23:54:49 GMT
From: "Big Jay" <jbredice@hotmail.com>
Subject: Using a variable to call a sub-routine...
Message-Id: <dP1Sf.1513$tN3.1066@newssvr27.news.prodigy.net>

Hi all,

I'm trying to call a sub-routine based on the value of a variable.

More specifically, I'm developing a menu system, where each level of the 
menu has it's own sub-routine, but for a generalized "back" function, I'm 
trying to call the last menu based on a variable, something like:

$lastMenu = apiMenu;

&$lastMenu; #I want this to be the same as calling &apiMenu

Does this make any sense?

Any help is greatly appreciated! 




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

Date: Thu, 16 Mar 2006 00:08:16 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Using a variable to call a sub-routine...
Message-Id: <Xns9787C2C9FE9FEasu1cornelledu@127.0.0.1>

"Big Jay" <jbredice@hotmail.com> wrote in
news:dP1Sf.1513$tN3.1066@newssvr27.news.prodigy.net: 

> I'm trying to call a sub-routine based on the value of a variable.
> 
> More specifically, I'm developing a menu system, where each level of
> the menu has it's own sub-routine, but for a generalized "back"
> function, I'm trying to call the last menu based on a variable,
> something like: 
> 
> $lastMenu = apiMenu;
> 
> &$lastMenu; #I want this to be the same as calling &apiMenu

Use a hash table to map menu names to menu handlers.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Thu, 16 Mar 2006 00:15:07 GMT
From: "Big Jay" <jbredice@hotmail.com>
Subject: Re: Using a variable to call a sub-routine...
Message-Id: <f62Sf.1519$tN3.495@newssvr27.news.prodigy.net>

I think I'll try making a default menu functions sub-routine and pass it 
arguments for things like last menu...  That should do the trick.

"Big Jay" <jbredice@hotmail.com> wrote in message 
news:dP1Sf.1513$tN3.1066@newssvr27.news.prodigy.net...
> Hi all,
>
> I'm trying to call a sub-routine based on the value of a variable.
>
> More specifically, I'm developing a menu system, where each level of the 
> menu has it's own sub-routine, but for a generalized "back" function, I'm 
> trying to call the last menu based on a variable, something like:
>
> $lastMenu = apiMenu;
>
> &$lastMenu; #I want this to be the same as calling &apiMenu
>
> Does this make any sense?
>
> Any help is greatly appreciated!
> 




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

Date: Wed, 15 Mar 2006 20:35:25 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Using a variable to call a sub-routine...
Message-Id: <nh3Sf.3644$fy1.214442@news20.bellglobal.com>


"Big Jay" <jbredice@hotmail.com> wrote in message 
news:dP1Sf.1513$tN3.1066@newssvr27.news.prodigy.net...
> Hi all,
>
> I'm trying to call a sub-routine based on the value of a variable.
>
> More specifically, I'm developing a menu system, where each level of the 
> menu has it's own sub-routine, but for a generalized "back" function, I'm 
> trying to call the last menu based on a variable, something like:
>
> $lastMenu = apiMenu;
>
> &$lastMenu; #I want this to be the same as calling &apiMenu
>
> Does this make any sense?
>

They're called symrefs, and they're to be avoided. It's always better to use 
a hash:

my %subs = ( apiMenu => \&apiMenu );
my $lastMenu = 'apiMenu';
$subs{$lastMenu}();

Matt 




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

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 V10 Issue 9056
***************************************


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