Gossamer Forum
Home : General : Perl Programming :

another perl question

(Page 2 of 2)
> >
Quote Reply
Re: [Andy] another perl question In reply to
think i figured it out
changed:
Code:
#foreach (split /\n/, $values) {
foreach (split /\n/, $fields) {
guess i don't need the line:
$file =~ m/\%db_radio_fields\s+=\s+\((.*?)\)/s and $values = $1;
Quote Reply
Re: [delicia] another perl question In reply to
everything is working great! thanks again for all your help!
Quote Reply
Re: [delicia] another perl question In reply to
Cool :) You would actually be better doing:

Code:
my ($fields,$body,$values,%new_hash);

# grab the contents, and store as $body - basically the same as file_slurp()
open(FILE, "<$configfile") || cgierr("Cannot open $configfile.\n$!");
while (<FILE>) { $body .= $_; }
close(FILE);

# grab the value back using a regex
$body =~ m/\%db_radio_fields\s+=\s+\((.*?)\)/s and $fields = $1;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] another perl question In reply to
ok, i changed and it still works! curious why that is better.
Quote Reply
Re: [delicia] another perl question In reply to
Hi,

Good to hear :)

1) Its cleaner code (easier to read back and edit in the future)
2) I'm not even sure how the other version of your code worked (you were doing the regex match in in the <while> loop, but it was iterating one line at a time)

Angelic

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] another perl question In reply to
ok, i'll change the other sub. so it's always better to read in the whole file first, then examine the lines, instead of reading and examining one line at a time? i notice in dbman sometimes it's done one way and sometimes the other.
Quote Reply
Re: [delicia] another perl question In reply to
Hi,

Yeah, well in this case you need the whole contents to be able to extract it using the regex - which is why I just used file_slurp().

Some places its good to do a while () loop, and process it line by line (for example, when reading a database file - as you don't need to wait on the next line to start doing work on the data). Other times (for example, reading a template) you would want to slurp it all into one variable, so you can process it all at once Angelic

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
> >