Professional Web Applications Themes

finding a spot in a file - PERL Beginners

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 ...

  1. #1

    Default Re: finding a spot in a file

    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
    John W. Krahn Guest

  2. #2

    Default Re: finding a spot in a file

    On Thu, 09 Oct 2003 21:12:38 -0400, chad kellerman wrote:
    > Can anyone point me in the right direction?
    Seems like you're trying to read a configuration file. There are modules
    to do that work for you. Check out CPAN.


    --
    Tore Aursand <toreaursand.no>

    Tore Aursand Guest

  3. #3

    Default Re: finding a spot in a file

    Chad Kellerman wrote:
    >
    > 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?
    Hi Chad.

    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

  4. #4

    Default 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]ckellermanalabanza.com[/email]


    Chad Kellerman Guest

Similar Threads

  1. Finding a Spot color Location
    By Matthew_Hunter@adobeforums.com in forum Adobe Indesign Windows
    Replies: 4
    Last Post: July 8th, 06:24 PM
  2. DCS File Not Saving All Spot Channels
    By Cheryl_Lehman@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 23
    Last Post: May 17th, 12:35 AM
  3. Saving a spot color file for use with InDesign 2/PDFs
    By Merrily_Schmid@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 2
    Last Post: April 7th, 04:38 PM
  4. imported photoshop eps spot file?
    By benluke@adobeforums.com in forum Adobe Indesign Windows
    Replies: 6
    Last Post: April 5th, 08:41 PM
  5. Limit to how many spot colours in an AICS eps file?
    By Tricia_Tahara@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 2
    Last Post: February 16th, 05:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139