string and hash [quite long]

N

No_name

Hi at hall, I am a beginner and I've got this problem: translate a string,
runtime generated by lsdvd program, into an hash. The string is similar at
this:
our %lsdvd = (
device => '/dev/dvd',
title => 'DVDVOLUME',
vmg_id => 'DVDVIDEO-VMG',
provider_id => '',
track => [
{
ix => 1,
length => 5309.090,
vts_id => 'DVDVIDEO-VTS',
},
{
ix => 2,
length => 22.050,
vts_id => 'DVDVIDEO-VTS',
},
{
ix => 3,
length => 63.060,
vts_id => 'DVDVIDEO-VTS',
},
{
ix => 4,
length => 181.280,
vts_id => 'DVDVIDEO-VTS',
},
{
ix => 5,
length => 181.280,
vts_id => 'DVDVIDEO-VTS',
},
],
longest_track => 1,
);
There is a way?

P.S. sorry for my poor English
 
P

Paul Lalli

No_name said:
Hi at hall, I am a beginner and I've got this problem: translate a string,
runtime generated by lsdvd program, into an hash. The string is similar at
this:
our %lsdvd = (
device => '/dev/dvd',
title => 'DVDVOLUME',
vmg_id => 'DVDVIDEO-VMG',
provider_id => '',
track => [
{
ix => 1,
length => 5309.090,
vts_id => 'DVDVIDEO-VTS',
},
],
longest_track => 1,
);
There is a way?

You want to take a string that looks like perl code and evaluate it as
perl code? Try:
perldoc -f eval

Paul Lalli
 
U

usenet

No_name said:
Hi at hall, I am a beginner and I've got this problem: translate a string,
runtime generated by lsdvd program...

Show us the output from your lsdvd program (this is NOT a standard UNIX
command - many folks won't have it on their systems).
 
R

robic0

Show us the output from your lsdvd program (this is NOT a standard UNIX
command - many folks won't have it on their systems).
Whats an "lsdvd"? Is it a cross between list dvd.* or
the lsd vd the preffered drug in the 60's?
 
N

No_name

robic0 said:
Whats an "lsdvd"? Is it a cross between list dvd.* or
the lsd vd the preffered drug in the 60's?
Funny, the second of course :)
No, I think the name came from list dvd.
 
U

usenet

No_name said:
Funny, the second of course :)
No, I think the name came from list dvd.

Well, I think we've established that none of the responders are
familiar with this 'lsdvd' command. But that doesn't mean we can't help
you answer your question. But we need to SEE the output from the
'lsdvd' command to offer you any meaningful help. You've been asked to
show this before. If you continue to deny this request, you won't get
any help.

Show us the output from the command. We can bump that against your
original post and point you in the right direction.
 
N

No_name

Show us the output from your lsdvd program (this is NOT a standard UNIX
command - many folks won't have it on their systems).
The string on the message starting with
"our %lsdvd = ("
and ending with
"longest_track => 1,);"
is the output of lsdvd program. It can be more complex (more field and
entries) but structure is the same.
 
N

No_name

Paul said:
No_name said:
Hi at hall, I am a beginner and I've got this problem: translate a
string, runtime generated by lsdvd program, into an hash. The string is
similar at this:
our %lsdvd = (
device => '/dev/dvd',
title => 'DVDVOLUME',
vmg_id => 'DVDVIDEO-VMG',
provider_id => '',
track => [
{
ix => 1,
length => 5309.090,
vts_id => 'DVDVIDEO-VTS',
},
],
longest_track => 1,
);
There is a way?

You want to take a string that looks like perl code and evaluate it as
perl code? Try:
perldoc -f eval

Paul Lalli
Yes the program can print out a string that is "perl code". I'll try eval.
Thanks
 
U

usenet

No_name said:
The string on the message starting with
"our %lsdvd = ("
and ending with
"longest_track => 1,);"
is the output of lsdvd program.

Oooohhhh! I thought that was an example of a Perl data structure that
you were trying to create from the program output. I thought you were
showing us what you wanted to get, not what you started out with.
Because this program output IS a Perl data structure (how convenient).

Then Paul Lali has already answered your question (ie, use "eval").
See the code below for an example. But how do you intend to use this
data structure? What do you want to do with it?


#!/usr/bin/perl
use warnings; use strict;

my $cmd = join " ", map {($_) =~ / *(.*)\n/} <DATA>;

my %dvd = eval $cmd;

use Data::Dumper; #to validate the effects
print Dumper(\%dvd); #is it really right??? Yes indeed!

__DATA__
device => '/dev/dvd',
title => 'DVDVOLUME',
vmg_id => 'DVDVIDEO-VMG',
provider_id => '',
track => [
{
ix => 1,
length => 5309.090,
vts_id => 'DVDVIDEO-VTS',
},
{
ix => 2,
length => 22.050,
vts_id => 'DVDVIDEO-VTS',
},
{
ix => 3,
length => 63.060,
vts_id => 'DVDVIDEO-VTS',
},
{
ix => 4,
length => 181.280,
vts_id => 'DVDVIDEO-VTS',
},
{
ix => 5,
length => 181.280,
vts_id => 'DVDVIDEO-VTS',
},
],
longest_track => 1,
 
N

No_name

Show us the output from the command.
************ this string is the program output *****************
our %lsdvd = (
device => '/dev/dvd',
title => 'DVDVOLUME',
vmg_id => 'DVDVIDEO-VMG',
provider_id => '',
[cut]
{
ix => 5,
length => 181.280,
vts_id => 'DVDVIDEO-VTS',
},
],
longest_track => 1,
);
****************************************************************
But don't warry, I've used "eval", as suggested Paul Lalli, and now it's ok.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top