- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: using structure on perl scripts
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2006 07:14 PM
тАО07-11-2006 07:14 PM
I'm trying to write a perl script using structure. (using Class::Struct)
the structure is defined as follows:
struct DiskAllocation =>
[
Disk => '$',
Fa => '@',
];
I'm using the following method to update the array (see also the function below)-
first I create another array,temporary, and then when I finish to fill it out with values, I copy the temporary array into the structure array.
I have two problems (so far...)
1. I cannot 'copy' the temporary array into the structure array, it ask me to use pointers instead. since it's a temporary array (and I want to use it afterwards), it's a problem
2. when attempting to reach data in the structure (from the 'Disk' field, which is an integer) I received the following warning (I still recieve the requested data)
Can't call method "Disk" on unblessed reference at DrpMan.pl line 219.
3. when attempting to read data from the Fa field (which is an array) I keep receving syntax errors, no matter how I try to read it.
this is the function I use to read/write the structure -
attched the section from the script, with the struct defintion and function
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 02:36 AM
тАО07-12-2006 02:36 AM
Re: using structure on perl scripts
but the biggest problem remains -
I can't assign an Array to structure array -
(by $Struct->new (array => @another_array
only by
$Struct->array=\@another_array)
which is not good!! since I need to clean '@another_array' from values, using refrences is not good for me...
Help me ppl!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 02:36 AM
тАО07-12-2006 02:36 AM
Re: using structure on perl scripts
but the biggest problem remains -
I can't assign an Array to structure array -
(by $Struct->new (array => @another_array
only by
$Struct->array=\@another_array)
which is not good!! since I need to clean '@another_array' from values, using refrences is not good for me...
Help me ppl!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 02:40 AM
тАО07-12-2006 02:40 AM
Re: using structure on perl scripts
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 03:00 AM
тАО07-12-2006 03:00 AM
Re: using structure on perl scripts
I receive the following error -
root@troya: perl DrpMan.pl
Can't modify non-lvalue subroutine call at DrpMan.pl line 219,
.
and line 219 -
$returnArray[$DiskCount]->Fa=[@Fa];
can I insert scalars values using the same syntax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 03:17 AM
тАО07-12-2006 03:17 AM
Re: using structure on perl scripts
if you have an array
my @disks = qw( /dev/dsk/c1t2d0 /media/usbdisk );
putting @disks in square brackets creates an array reference to a list of copies of the elements in @disks
lt09:/home/merijn 101 > perl -MData::Dumper -e'@x=qw(foo bar);print Dumper@x'
$VAR1 = 'foo';
$VAR2 = 'bar';
lt09:/home/merijn 102 > perl -MData::Dumper -e'@x=qw(foo bar);print Dumper\@x'
$VAR1 = [
'foo',
'bar'
];
lt09:/home/merijn 103 >
You could play with Data::Dumper and see what it expects
Still, why the need for struct?
my $ref = (
Array => [ qw( foo bar ) ],
Count => 2,
Info => {
Author => "Tux",
Company => "PROCURA",
ID => "BR41967",
Number => 42,
List => [ 1 .. 16 ],
},
Valid => 1,
);
if ($ref->{Info}{Author} eq "Tux" &&
$ref->{Array}[1] eq "bar" &&
$ref=>{Info}{List}[2] == 2) {
print "See, it's that simple!
$ref->{Extra_Info}{Age}[24] = 42;
}
}
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 07:27 AM
тАО07-12-2006 07:27 AM
Re: using structure on perl scripts
I need to design a utility to hold a lot of data on real time (not on any kind of third party database) regrading to my storage enviorment. I need to make some queires against this 'database' (we'll use that on a crisis, when we'll have to establish a DRP site ). I started writing this proggram and I came out with some complex data holders such as three dimensional arrays of hashes, I'm looking for a better way, that is easier to manage.
I didn't understand if the soultion u've wrote is an explantion of how using structure or if it's an alternative soultion.
thanks!
itai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 07:33 AM
тАО07-12-2006 07:33 AM
Re: using structure on perl scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 07:36 AM
тАО07-12-2006 07:36 AM
Re: using structure on perl scripts
the M comes from the command line option -M, which is a shorthand for "use Module"
see "man perlrun" for more details.
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 07:40 AM
тАО07-12-2006 07:40 AM
Re: using structure on perl scripts
By putting your array in [ ] creates an array reference list of copies of your arrays elements.
It sounds confusing buts its really not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 07:40 AM
тАО07-12-2006 07:40 AM
Re: using structure on perl scripts
use Data::Dumper
...its a module in your core distribution used to "dump" (show) data.
# perldoc Data::Dumper
...will show you details.
The use of:
# perl -MData::Dumper -e ' ... '
...says to use the (M)odule whose name follows, just like 'use Data::Dumper;'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 04:10 PM
тАО07-12-2006 04:10 PM
Re: using structure on perl scripts
I would love not to use that complicated module, but I still don't see how can I do that otherwise.(I understood how can I copy a whole array, but I need more than that)
by 'sturct' I mean Data Structure, like what we had on C, before we had C++/Java objects -
in C - for instnace - If I want to describe a person, that has a name,an age and an ID -
typedef struct person
{
char* name;
float age;
int id;
}PERSON;
and then acessing to data for read and write is very easy using the '->' operator, it's like a primitive object. I can also make an array of structures)
I just need a solution for complex data structures, variables with fixed attributs, like forms. (varibles that can be consist of strings, arrays and hashes, the same time to be a value of one array cell, I can acehive it by doing arrays of hashes, but it's not that easy to manage)
thanks
Itai.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 06:18 PM
тАО07-12-2006 06:18 PM
SolutionWhat you /can/ do is build your own module, and give it an OO look, so you can do exactly as you say.
If you are seriously going to convert C++ to perl on a larger scale, I'd advice you to read Damien Conway's "Object Oriented Programming in Perl" from Manning books.
For the shor term, perl comes with quite a lot of on-line documentation about this.
Data Structure Cookbook:
# perldoc perldsc
Perl Objects
# perldoc perlobj
Beginner's Object-Oriented Tutorial
# perldoc perlboot
Tom's object-oriented tutorial for perl
# perldoc perltoot
Tom's OO Tutorial for Class Data in Perl
# perldsc perltooc
You can also use man on most systems
# man perldsc
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 09:51 PM
тАО07-12-2006 09:51 PM
Re: using structure on perl scripts
then there's really no need for the module you chose to import.
Since the transition from Perl4 to Perl5 Perl got references which let you build up even deeply nested LoLs on the fly.
Besides, refernces are the main feature how Perl implements OO.
Unlike other languages Perl's has no formal OO constructs (the widespread "new" for a class method or constructor is merely a convention to make life easier for C++ hackers).
In Perl you only need to "bless" any type of variable reference (it even works with filehandles) into a package (which is only the class'es namespace).
Because of this liberty (which follows Perl's TIMTOWTDI motto) it can make it a bit difficult for programmers comming from more formal OO languages, to whom it may look quite chaotic.
That's why there are modules like Class::Struct.
Although I have never used this module (and haven't read its POD yet) I assume that it merely acts as a nicer interface to creating class data than the rugged Perlish way of creating and initiating a hasref (usually called $self, but that's only another liberal convention) in the class constructor.
If you don't plan to write an OO module than I think Class::Struct isn't of much use for you.
A simple C struct translates to a hash in Perl.
If you need a nested struct then the values of the hash simply need to become references to lists, either arrayrefs (designated by angular brackets []), or hashrefs (designated by curly brackets {}).
You should have a deko at the perldocs procura gave you.
As far as OO programming in Perl is concerned I would aggree that probably the best reference material (apart from perldocs like perlboot, perltoot, perltooc) is the mentioned book by Damian Conway.
Also looking at the implementation of modules by CPAN authors like Damian is very instructive.