Ask a Question related to PERL Beginners, Design and Development.
-
John W. Krahn #1
Re: finding a spot in a file
Chad Kellerman wrote:
Hello,>
> Hello,
You could use a module like> I am opening up a file (actually a my.conf). I only want 2 lines in
> the file. port and datadir
>
> The problem I am running into is that there is a port = 3324 in both
> the [client] section and the [mysqld] section.
>
> I want to open the file and go straight to the [mysqld] section and
> grab the values for port and datadir.
>
> Can anyone point me in the right direction?
[url]http://search.cpan.org/author/WADG/Config-IniFiles-2.38/IniFiles.pm[/url] or
[url]http://search.cpan.org/author/SHERZODR/Config-Simple-4.55/Simple.pm[/url]
Or something like this may work:
$/ = '[';
my ( $port, $datadir );
while ( <FILE> ) {
if ( /mysqld]/ ) {
$port = $1 if /^port\s*=\s*(\d+)/m;
$datadir = $1 if /^datadir\s*=\s*(.+)/m;
}
}
John
--
use Perl;
program
fulfillment
John W. Krahn Guest
-
Finding a Spot color Location
Is there an easy way to find and change objects in a document making use of a specific spot color I inherited a document that has two spot colors... -
DCS File Not Saving All Spot Channels
Help! I have a client who wanted to colorize a black and white drawing in order to print in spot colors...Now he wants to print in process because... -
Saving a spot color file for use with InDesign 2/PDFs
We are updating old PageMaker documents in which we had placed 2 color spot color DCS files from Photoshop. A while back I had asked in the InDesign... -
imported photoshop eps spot file?
I am putting together a 2 colour document, When i import the eps file it appears in black and white. Is this normal? or am i doing someting wrong? ... -
Limit to how many spot colours in an AICS eps file?
Hi there. For the 2nd time I've had to use AI9 to make an eps or ps file from an AI file with lots of spot colours. The first time I was trying to... -
Tore Aursand #2
Re: finding a spot in a file
On Thu, 09 Oct 2003 21:12:38 -0400, chad kellerman wrote:
Seems like you're trying to read a configuration file. There are modules> Can anyone point me in the right direction?
to do that work for you. Check out CPAN.
--
Tore Aursand <tore@aursand.no>
Tore Aursand Guest
-
Rob Dixon #3
Re: finding a spot in a file
Chad Kellerman wrote:
Hi Chad.>
> I am opening up a file (actually a my.conf). I only want 2
> lines in the file. port and datadir
>
> The problem I am running into is that there is a
> port = 3324 in both the [client] section and the [mysqld]
> section.
>
> I want to open the file and go straight to the [mysqld]
> section and grab the values for port and datadir.
>
> Can anyone point me in the right direction?
Does something like this help? It relies on both values
actually being present in the section.
Cheers,
Rob
use strict;
use warnings;
open CONF, 'my.conf' or die $!;
$_ = <CONF> until /\Q[mysqld]/;
my $port;
my $datadir;
while (<CONF>) {
chomp;
$port = $_ if /\bport\s*=/;
$datadir = $_ if /\bdatadir\s*=/;
last if $port and $datadir;
}
Rob Dixon Guest
-
Chad Kellerman #4
Re: finding a spot in a file
John,
Thanks that was perfect..
Chad
On Fri, 2003-10-10 at 03:11, John W. Krahn wrote:--> Chad Kellerman wrote:>> >
> > Hello,
> Hello,
>>> > I am opening up a file (actually a my.conf). I only want 2 lines in
> > the file. port and datadir
> >
> > The problem I am running into is that there is a port = 3324 in both
> > the [client] section and the [mysqld] section.
> >
> > I want to open the file and go straight to the [mysqld] section and
> > grab the values for port and datadir.
> >
> > Can anyone point me in the right direction?
> You could use a module like
> [url]http://search.cpan.org/author/WADG/Config-IniFiles-2.38/IniFiles.pm[/url] or
> [url]http://search.cpan.org/author/SHERZODR/Config-Simple-4.55/Simple.pm[/url]
>
> Or something like this may work:
>
> $/ = '[';
> my ( $port, $datadir );
> while ( <FILE> ) {
> if ( /mysqld]/ ) {
> $port = $1 if /^port\s*=\s*(\d+)/m;
> $datadir = $1 if /^datadir\s*=\s*(.+)/m;
> }
> }
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
Chad Kellerman
Systems Administration / Network Operations Manager
Alabanza Inc.
10 E Baltimore Street
Baltimore, Md 21202
Phone: 410-234-3305
Email: [email]ckellerman@alabanza.com[/email]
Chad Kellerman Guest



Reply With Quote

