IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesPerlData Structures  Print This     

Cross Ref > Data Structures

By Mike Prestwood

Perl versus PHP: A side by side comparison between Perl and PHP.

 
Data Structures
 

Data structures allow you to store and work with data. Common data structures include arrays, associative arrays, etc.

Associative Array

[Other Languages] 
A set of unique keys linked to a set of values. Each unique key is associated with a value. Think of it as a two column table. MyArray['CA'] = 'California' MyArray['AR'] = 'Arizona'

Languages Focus

Associative arrays are also known as a dictionary or a hash table in other languages.

Perl:   % Array Preface
Syntax Example:
my %weekdays = (
'Sun' => 'Sunday',
'Mon' => 'Monday',
'Tue' => 'Tuesday',
'Wed' => 'Wednesday',
'Thu' => 'Thursday',
'Fri' => 'Friday',
'Sat' => 'Saturday',
);
my $day_of_the_week = $weekdays{'Mon'};
PHP: 

Declare associative array with initial known values. You can also add to associative array. (You can just assign values without ever declaring it too!)

Syntax Example:
$prices = array( 'Tires'=>100, 'Spark Plugs'=>4 );
$prices['Oil'] = 10;
 
echo "Tires=" . $prices['Tires'] . "<br>";
echo "Oil=" . $prices['Oil'] . "<br>";




Pointers

[Other Languages] 

General Info: Pointers / References

A pointer is a variable type that allows you to refer indirectly to another object. Instead of holding data, a pointer holds the address to data -- the address of another variable or object. You can change the address value a pointer points to thus changing the variable or object the pointer is pointing to.

A reference is a type of pointer that cannot change and it must always point to a valid storage (no nulls).

Perl: 

Perl supports both pointers and references.

PHP:   Not Supported

PHP supports references which allow you to refer to the value of a variable but PHP does not support true developer defined pointers. You cannot get and use the address of a variable.

However, you can still do inexpensive assignments by assigning by reference.





Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]