sed command in perl script

What is wrong with this line in a perl script?

 
$amc_data = `sed -n '/\[Amc\]/,/\[\/Amc\]/p' "$config_file"`

I ran the above from command line and it works fine from unix command prompt.
The code should produce output between the [Amc] and [/Amc] tags.

The config_file is as follows:

 
[Amc]
Sun     0000-2359
Mon     0000-0859;1830-2359
Tue     0000-2359;1830-2359
Wed     0000-2359;1830-2359
Thu     0000-2359;1830-2359
Fri     0000-2359;1830-2359
Sat     0000-2359
[/Amc]
[Dummy]
Sun     0000-2359
Mon     0000-0859;1830-2359
Tue     0000-2359;1830-2359
Wed     0000-2359;1830-2359
Thu     0000-2359;1830-2359
Fri     0000-2359;1830-2359
Sat     0000-2359
[/Dummy]

Hello,

First of all read it in list context. It would be easier to parse it afterwards.

I would suggest you use a perl one liner only . Incorporate this logic in your script or use a sed module. using a shell command would probably make it slower.

gaurav@localhost:~$ perl -wln -e 'BEGIN{my $flag=0;my @amc_data=();}$flag=1 if /\[Amc\]/;push(@amc_data,$_) if $flag==1;$flag=0 if /\[\/Amc\]/;END{print @amc_data;}' amc 

So your code would look like

my $flag=0;
my $arr=();
$flag=1 if /\[Amc\]/;
push(@amc_data,$_) if $flag==1;
$flag=0 if /\[\/Amc\]/; 

This is exactly what sed does.

Regards,
Gaurav.

Hi,
Thanks for your reply but I did not understand how the script will work.
Can you please explain?