stargeek
PHP news website logo.
home    PHP scripts    articles    seo tools    links    search    contact    shop    realtors


Perl's Special Variables







Perl's Special Variables

Perl's Special Variables 06/18/2004 07:05 PM

Dave Cross goes back to basics to show how using Perl's special variables can tidy up file-handling code.




This is a GrokNews Entry: (what is grok?)





Similar Items

Perl's Special Variables

Grok Headline matches for Perl's Special Variables

Perl's Extreme Makeover


Perl's Extreme Makeover 02/18/2004 04:06 PM

Parsing XML documents with Perl's
XML::Simple


Parsing XML documents with Perl's
XML::Simple
09/20/2004 12:46 AM
CNET Sep 20 2004 4:09AM GMT

Reading ID3 tags with Perl's MP3::Tag
module


Reading ID3 tags with Perl's MP3::Tag
module
08/23/2004 02:46 AM
CNET Aug 23 2004 7:14AM GMT

Discover Perl's File::Find module


Discover Perl's File::Find module 09/14/2002 11:12 PM
CNET Sep 14 2002 10:03PM ET

PHP Application Variables


PHP Application Variables 07/02/2002 09:57 AM

Predefined Variables


Predefined Variables 06/09/2004 03:40 PM

Variable Variables in PHP


Variable Variables in PHP 12/19/2002 10:43 PM
Variable Variables in PHP Well since it's late but I'm still grinding and I feel guilty for not blogging much today, here's a special PHP Treat: A Variable Variable Tutorial. Yes that's right. There is a feature in PHP called "Variable Variables". One of the issues that I had with implementing our Digibuy support was our old friend and enemy: Parsing. This is such a fundamental thing but there always seems to be a new wrinkle in it. In this case we had an existing PHP script which did our registration calculations and was expecting a certain set of variables. Now this code was fairly complex and I didn't want to re-write it (much). Here's the input data we had to parse: author_id=BillBrown & author_password=HemosRules & prod_sku=98079949999 With the exception that it had like 30 odd variables in it. Since my code was expecting a series of variables I needed to parse this and automatically create a series of variables like $author_id and $author_password. Now if this data was being given to me by a URL then it would be easy -- PHP could automatically do it or I could just pull them out of $_REQUEST. But, instead, I had them going to me as if they were a file. So ... How do you create a series of variables on the fly? Note: Yes I could have made an associative array but that wouldn't have taught me anything, now would it ? I could also have gotten a similar effect with the extract function but I found out about that after this working. And if the code is working then ... Well deep in the recesses of what I call a brain was a recollection of "variable variables". I think I heard about this in a talk that Rasmus gave although I can't honestly be sure. I do know that whenever you need to do "meta" type tasks like this in a language, you need to poke around the oddball features since that's usually where they reside. What I do is look for the sections of the documentation that I've never read. The idea behind a variable variable is simple: interpret the value of a variable and make it into a variable itself. I.e. the "variable variable" nomenclature. Since php uses $ for indicating a variable they've chosen to use $$ to make a variable variable. Let's say you have two variables, $part1 and $part2. If $part1 = "author_id" and $part2="HemosRules" how do I get to $author_id = "HemosRules". Simple: $$part1 = $part2. Yup. It's just that easy. Of course I did need to wrap it into a string parsing loop. Here's the guts of it: $strarray = explode("&",$input); foreach ($strarray as $stritem) { $stritem = trim($stritem); $part1 = substr ( $stritem, 0, strpos ( $stritem,"=" ) ); $part2 = substr ( $stritem, strpos ( $stritem,"=" )+1, strlen ( $stritem ) ); #magic! $$ is a "variable variable" i.e. it converts the value #in the variable into a variable itself $$part1 = $part2; } The way this works is an input string, $input, contains everything that needs to be processed. First I explode this into an array using "&" as the delimiter. Then I loop over the array with a foreach loop creating a $part1 variable and a $part2 variable. Finally I just do the magic $$part1 = $part2. Here's the example Source Code. Here's the working Example Thanks again to my favorite Systems Administrator, Apokalyptik, for showing me how to use PHP to generate code listings. Much easier than pasting it into a blog entry. More on Variable Variables from PHP.Net: [_Go_] Variable Variables. A little confusing but definitely a frothy good thing!

Object-Variables-0.9


Object-Variables-0.9 07/30/2004 12:14 AM

Object-Variables-0.5


Object-Variables-0.5 07/27/2004 12:28 AM

An Introduction to Variables


An Introduction to Variables 11/27/2002 09:47 PM

This is only for those who are new to php, or maybe programming altogether. This won't 'enlighten' you, or make you 'one with everything', but it should make you one with variables.


Variables and Paths


Variables and Paths 06/26/2002 07:05 PM
In this month's Q&A column, John Simpson answers questions about XSLT variables and XML document paths.

Application Variables in PHP


Application Variables in PHP 07/01/2002 08:29 AM
This is the first article of several on developing an architecture for Enterprise PHP, where we are running dedicated PHP servers tuned to serve large number of web pages. This work originated in the need to save the current working database connection as an Application variable in a primary and fallback database server configuration. This can be extended to saving other configuration information that rarely changes... -- John Lim

"zeldman.jayne"

Application Variables with PHP


Application Variables with PHP 08/05/2002 10:44 PM
One of the most common feature requests that PHP developers ask for is application variables. These are variables that are globally available to all PHP scripts on a web server. There are currently several implementations.

Tunneling Variables


Tunneling Variables 04/09/2004 04:09 PM
In Bob DuCharme's latest Transforming XML column he explains the use and virtues of XSLT 2.0's tunneled variables.

Object-Variables-0.4


Object-Variables-0.4 07/25/2004 06:12 AM

Internal Variables for Use in Your
Scripts


Internal Variables for Use in Your
Scripts
08/15/2004 07:36 PM

Hash variables in Perl


Hash variables in Perl 08/23/2004 02:48 AM
CNET Aug 23 2004 7:15AM GMT

PHP Static Class Variables


PHP Static Class Variables 12/02/2002 01:17 PM
Static class variables are variables that are shared among all instances of a particular class. Although PHP supports static variables in functions, it has no support for static variables in classes. This functionality can be pretty important in some situations, and I will now describe a way to simulate it.

Using hash variables in Perl


Using hash variables in Perl 05/03/2004 09:19 AM
CNET May 3 2004 1:48PM GMT

Variables used by the Status Filter


Variables used by the Status Filter 04/15/2004 02:26 PM

Using variables in Windows batch files


Using variables in Windows batch files 08/29/2004 02:23 PM
Tech-Recipes Aug 29 2004 6:35PM GMT

A Guide to Basic Variables That Add To
Site Value


A Guide to Basic Variables That Add To
Site Value
03/17/2005 02:32 AM
Nice checklist of items to cover before buying or selling a site.

Templates with patTemplate, and Form
Variables


Templates with patTemplate, and Form
Variables
05/30/2002 08:10 AM

Learning Cocoa: Repurposing Variables


Learning Cocoa: Repurposing Variables 01/18/2004 02:48 PM
Set Roby: "By now we know that every variable is really just a bunch of bits, which we can look at a certain way and read as an integer, a pointer, or whatever else we need to remember. Well, what else do we want to remember?"

The Fuzzy Blog on Varaible Variables


The Fuzzy Blog on Varaible Variables 12/20/2002 08:49 AM

SysAdmin to SysAdmin: Perl's Tie::File
module


SysAdmin to SysAdmin: Perl's Tie::File
module
06/02/2004 03:50 AM
Two factors outshine all others as reasons I became a systems administrator. The first is that, well, I like computers and computing. The second is that I'm not particularly fond of writing code. If I were, I'd probably be a programmer. As it stands, if I can find tools that work, I won't write code. However, inevitably, some site-specific situation will come up for which I have no choice. In that case, I at least want to write very little code. Perl's Tie::File has helped me do that on more than one occasion.

Unprivilegued settings for FreeBSD
kernel variables


Unprivilegued settings for FreeBSD
kernel variables
06/15/2004 01:41 PM
Radko Keves (Jun 14 2004)

Working with Environment variables -
Add, Remove and Retrieve


Working with Environment variables -
Add, Remove and Retrieve
12/24/2004 12:49 PM

Re: Unprivilegued settings for FreeBSD
kernel variables


Re: Unprivilegued settings for FreeBSD
kernel variables
06/16/2004 06:16 PM
Dag-Erling Smørgrav (Jun 15 2004)

Keep track of stopped processes via
shell variables


Keep track of stopped processes via
shell variables
12/15/2003 11:45 AM
Earlier hints discuss how to suspend and resume processes via kill -- very helpful to me, because I had been launching apps from Terminal and using ^Z, fg and bg to manage them. A summary of previous hints: kill -STOP and kil...

Setting the %DSDIT%, %DSLOG%, and
%SYSVOL% Variables


Setting the %DSDIT%, %DSLOG%, and
%SYSVOL% Variables
09/10/2004 01:53 AM

Copy variables from command line to GUI
environments


Copy variables from command line to GUI
environments
07/22/2004 09:59 AM
If you use the UNIX command line environment under OS X, you probably know that the environment symbols you set up in your .bashrc file are not reflected in the GUI environment. In the GUI environment, symbol values are read...

MDN: Special


MDN: Special 06/22/2005 02:21 AM

For that special someone


For that special someone 12/12/2003 05:39 AM
Oh Come All Ye faithful

comeallyefaithful.co.uk
track this site | 4 links


Round Up: Not that special


Round Up: Not that special 06/16/2004 06:08 PM
newmediazero Jun 16 2004 9:21PM GMT

Special effects


Special effects 11/17/2003 05:44 AM
Macleans Online Nov 17 2003 5:12AM ET

Kellogg's Special K Day


Kellogg's Special K Day 04/22/2004 12:04 PM
The food maker delivers some energized earnings.

Disappearing: Her Special Act


Disappearing: Her Special Act 07/08/2004 07:17 PM
The best of her Conceptualist art, as seen at the Whitney Museum, takes the form of outdoor performances and site-specific sculptures.

a special section


a special section 12/31/2004 12:43 PM
LabourStart

labourstart.org/tsunami
track this site | 3 links


Grok Description matches for Perl's Special Variables
GrokA matches for Perl's Special Variables

Perl's Special Variables

The following phrases have been identified by the grok system as matching this entry:

















Also check out:


Grok

Ipod Porn on the
Rise

Brief Abstract of
Wikipedia's
Mesothelioma Cancer
page

Get first aid
instructions in your
cell phone

IE is crap
JSPWiki gains
podcasting support

Steve Jobs Is
Overpaid While Larry
Ellison Is Underpaid

Stealth Wallpaper
SanDisk Wi-Fi SD
Card Works with
Palm--One Model, At
Least

Partly Cloudy
Identity and Email
Cold IM
Briefly:
Controversial
Accenture deal moves
ahead

nice eweek story on
MT's new prices

migrate your MT2.x
blog to MT3

FOXNews.com - U.S.
& World -
Report: Body of
Beheaded American
Found

DRUDGE REPORT FLASH
2002

Guardian | Oil
chief: my fears for
planet

Questions Regarding
the Shirts and
Membership

Blair hails EU
constitution deal

US 'to fight back'
in cotton war

Report: VOIP Phones
Won't Gain Lead
Until 2009

the ascendance of
labels over folders

Site-Flavored Google
Search

good thinking on
syndication and
identity

CBS only runs
anti-left advocacy
ads

how to choose
between MT and
TypePad

NetCLI 0.1
JavaZoneWriter 0.1
Syslinux 2.10
Sunbeams, Rare Goats
Edition

9/11 Report Cited No
Iraqi 'Control' of
Qaeda - Rice
(Reuters)

Saudi Says Top Al
Qaeda Leader Muqrin
Killed (Reuters)

al-Qaida Leader
Killed in Saudi Raid
(AP)

Q&A: GM security
chief says
cyberthreats lead to
change

Red Hat Linux topped
300,000 subscribers
in Q1

IBM to launch a
managed e-mail
filtering service

Airlines, airports
battle over Wi-Fi
spectrum oversight

France looks to
open-source in
challenge to
Microsoft

Speed record set for
public network data
transfer

SIA asks feds to
prod automation of
stock trades

NYC wireless network
will be
unprecedented

Re: Problem With IP
Logging In Invision
Power Board?

CRM Best Practices:
Getting the Best
Deal (NewsFactor)

Witness Sees Oracle
Gaining Control (AP)

Intel Unveils PC
chips (NewsFactor)

Google Launches
Tools to Boost
Online Search, Ads
(Reuters)

PeopleSoft Top
Restraint on
Oracle-Economist
(Reuters)

Lessig speaks on
tech IP law and
indie filmmaking at
LA Film Festival

International PHP
Conference 2004

A Clash in
Civilization

Crews Struggle to
Fix Iraq Oil
Pipelines

Court Rules That
Connecticut Governor
Must Testify

Internet Marketing
For Micro Businesses

Yahoo Leaves
Enterprise IM

NEC counters Nokia's
Japanese attack

what is grok?