|
Posted by Frank Seitz on March 6, 2008, 4:12 am
Please log in for more thread options
Rose wrote:
>
> But can I use a for loop to achieve the following effect? I guess I can't
> simply code:
> $panel->add_track([@obj],
> -label => 1,
> );
>
> $panel->add_track([$obj1,$obj2,$obj3, ..., $objn],
> -label => 1,
> );
Can't tell. What expects add_track() as second parameter?
(first parameter is the ref to the panel-Object)
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/ Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
|
|
Posted by Rose on March 6, 2008, 4:39 am
Please log in for more thread options
> Rose wrote:
>>
>> But can I use a for loop to achieve the following effect? I guess I can't
>> simply code:
>> $panel->add_track([@obj],
>> -label => 1,
>> );
>>
>> $panel->add_track([$obj1,$obj2,$obj3, ..., $objn],
>> -label => 1,
>> );
>
> Can't tell. What expects add_track() as second parameter?
> (first parameter is the ref to the panel-Object)
>
> Frank
> --
> Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
> Anwendungen für Ihr Internet und Intranet
> Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
It can accept a number of objects $obj1,$obj2, ..., $objn in square
brackets. the problem is that "n" is unknown beforehand, and therefore can't
be hard-coded. I know that in Matlab a function called repmat may help...
|
|
Posted by Frank Seitz on March 6, 2008, 4:44 am
Please log in for more thread options Rose wrote:
>
> It can accept a number of objects $obj1,$obj2, ..., $objn in square
> brackets.
$panel->add_track(\@obj,...);
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/ Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
|
|
Posted by Ben Morrow on March 6, 2008, 4:59 am
Please log in for more thread options [please don't quote signatures]
> > Rose wrote:
> >>
> >> But can I use a for loop to achieve the following effect? I guess I can't
> >> simply code:
> >> $panel->add_track([@obj],
> >> -label => 1,
> >> );
> >>
> >> $panel->add_track([$obj1,$obj2,$obj3, ..., $objn],
> >> -label => 1,
> >> );
> >
> > Can't tell. What expects add_track() as second parameter?
> > (first parameter is the ref to the panel-Object)
>
> It can accept a number of objects $obj1,$obj2, ..., $objn in square
> brackets. the problem is that "n" is unknown beforehand, and therefore can't
> be hard-coded. I know that in Matlab a function called repmat may help...
If you have an array
@obj = (1, 2, 3, 4);
then the expression
[1, 2, 3, 4]
is exactly equivalent to
[@obj]
. This is generally true: whenever you have a series of comma-separated
items in list context, you can insert an array into the list and it will
be interpolated. The exception is the argument lists of functions like
'push' which have prototypes and so treat literal arrays specially.
Under many circumstances, it would be better to use
\@obj
as this doesn't make a copy of the array. You can do this if you know
the function you are calling doesn't modify the passed-in array (or if
you don't care if it trashes @obj).
Note that @obj is *not* equivalent to
$obj1, $obj2, $obj3, ...
if you were thinking that; $obj[1] is not the same as $obj1. If those
variables weren't just an example, they should have been in an array to
start with.
I would suggest you read perldoc perldsc and perldoc perlreftut.
Ben
|
|
Posted by ccc31807 on March 6, 2008, 8:30 am
Please log in for more thread options >
>
>
>
> > Rose wrote:
> >> I have to add objects dynamically in a code and therefore the number of=
> >> objects are not known beforehand. How to achieve this effectly in a
> >> simple
> >> way? e.g.
>
> > my $panel =3D Panel->new(...);
>
> > my @arr =3D ([10,10,'C'],[88,89,'T'],...);
> > for my $e (@arr) {
> > my $obj =3D Object::Generic->new(
> > -start=3D>$e->[0],
> > -end=3D>$e->[1],
> > -display_name=3D>$e->[2],
> > );
> > $panel->add_obj($obj);
> > }
>
> > Frank
> > --
> > Dipl.-Inform. Frank Seitz;http://www.fseitz.de/
> > Anwendungen f=FCr Ihr Internet und Intranet
> > Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
>
> Frank, Thanks a lot for your response. Indeed, @arr is not known beforehan=
d
> and the content of @arr is generated by another perlscript. How would you
> recommend to bridge these 2 perlscripts? The first one, I store the 10, 88=
,
> ...; 10, 89, ...; and C, T, ... into separate arrays, say @a1, @a2, @a3. A=
> simple but dirty way is to copy the contents of the 1st file to the 2nd an=
d
> then @arr =3D (@a1, @a2, @a3), but this does not look to be a good practic=
e.
In the first script, write the array to a text file, values space
separated with each list on a new line, like this:
20 30 A
40 50 B
60 70 C
=2E.. etc
In the second script, read in the file line by line and recreate the
data structure possibly as an array composed of array references.
I assume that you can read and write to a text file in your directory,
and that you will overwrite the same file each day so you can use
static file names.
CC
|
| Similar Threads | Posted | | how to "see" DOS errorlevel codes? | January 15, 2007, 12:17 pm |
| Help writing semaphore codes | July 12, 2007, 5:27 pm |
| Help: Debug perl codes | August 17, 2008, 8:15 am |
| Fork, processes and exit codes? | February 3, 2005, 2:36 am |
| Text descriptions of signal codes? | July 27, 2006, 12:11 pm |
| How to get the return codes for shell commands | January 19, 2007, 7:24 am |
| translating MS Word codes using regexps | April 27, 2007, 8:05 am |
| Dynamically Generating A Format | February 8, 2005, 7:33 pm |
| Online forum source codes in Perl/CGI without SQL? | October 23, 2004, 12:00 am |
| Making Net::SMTP Robust: Return Codes | May 27, 2005, 12:16 pm |
|